cuke4duke 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENCE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2008,2009 Aslak Hellesøy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.textile ADDED
@@ -0,0 +1,53 @@
1
+ h1. Cuke4Duke
2
+
3
+ Cuke4Duke is an addon to Cucumber, making it possible to write step definitions in several different JVM languages.
4
+
5
+ h2. Building Cuke4Duke
6
+
7
+ First of all, you need "Maven":http://maven.apache.org/ installed.
8
+ Then you'll need "git":http://git-scm.com/
9
+
10
+ You'll also need "JRuby":http://jruby.org installed to build Cuke4Duke. If you're on OS X or Linux it's recommended you install JRuby
11
+ with "RVM":http://rvm.beginrescueend.com
12
+
13
+ With JRuby installed - bootstrap your environment by installing some gems:
14
+
15
+ Using RVM:
16
+ <pre>gem install bundler && bundle install</pre>
17
+
18
+ Not using RVM:
19
+ <pre>jruby -S gem install bundler && jruby -S bundle install</pre>
20
+
21
+ With the gems installed, build the whole shebang (including the examples):
22
+
23
+ Using RVM:
24
+ <pre>rake build_all</pre>
25
+
26
+ Not using RVM:
27
+ <pre>jruby -S rake build_all</pre>
28
+
29
+ h2. Release process
30
+
31
+ First, bump the release number:
32
+
33
+ <pre>rake remove_snapshots</pre>
34
+
35
+ Build again:
36
+
37
+ <pre>rake build_all</pre>
38
+
39
+ If all is OK, commit:
40
+
41
+ <pre>git commit -am "Release"</pre>
42
+
43
+ And release:
44
+
45
+ <pre>rake release</pre>
46
+
47
+ Finally, bump version:
48
+
49
+ <pre>rake add_snapshots</pre>
50
+
51
+ And commit again:
52
+
53
+ <pre>git commit -am "Starting new development cycle"</pre>
data/bin/cuke4duke ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift(File.dirname(__FILE__) + '/../lib') unless $:.include?(File.dirname(__FILE__) + '/../lib')
3
+ require 'cuke4duke'
4
+ load Cucumber::BINARY
data/lib/.gitignore ADDED
@@ -0,0 +1 @@
1
+ cuke4duke-*.jar
@@ -0,0 +1 @@
1
+ require 'cucumber/jvm_support/backtrace_filter'
@@ -0,0 +1,30 @@
1
+ require 'cuke4duke/language_proxy'
2
+
3
+ Cuke4Duke.cuke4!('class')
4
+
5
+ module Cucumber
6
+ module ClassSupport
7
+ class ClassLanguage
8
+ class << self
9
+ attr_reader :snippet_generator, :analyzers
10
+
11
+ def add_analyzers(analyzer)
12
+ @analyzers ||= []
13
+ @analyzers << analyzer
14
+ @snippet_generator = analyzer.snippet_generator
15
+ end
16
+ end
17
+
18
+ def initialize(step_mother)
19
+ @delegate = Java.cuke4duke.internal.jvmclass.ClassLanguage.new(self, Java.cuke4duke.spi.jruby.JRubyExceptionFactory.new, step_mother, self.class.analyzers)
20
+ end
21
+
22
+ def snippet_text(step_keyword, step_name, multiline_arg_class = nil)
23
+ self.class.snippet_generator.snippet_text(step_keyword, step_name, multiline_arg_class)
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ require 'cucumber/java_support/java_analyzer'
30
+ require 'cucumber/scala_support/scala_analyzer'
@@ -0,0 +1 @@
1
+ require 'cucumber/jvm_support/backtrace_filter'
@@ -0,0 +1,3 @@
1
+ require 'cuke4duke/language_proxy'
2
+
3
+ Cuke4Duke.cuke4!('clj')
@@ -0,0 +1,2 @@
1
+ require 'cucumber/jvm_support/backtrace_filter'
2
+ Cucumber::Ast::StepInvocation::BACKTRACE_FILTER_PATTERNS << /org\/codehaus\/groovy|groovy\/lang/
@@ -0,0 +1,3 @@
1
+ require 'cuke4duke/language_proxy'
2
+
3
+ Cuke4Duke.cuke4!('groovy')
@@ -0,0 +1 @@
1
+ require 'cucumber/jvm_support/backtrace_filter'
@@ -0,0 +1,16 @@
1
+ require 'cuke4duke/language_proxy'
2
+
3
+ Cuke4Duke.cuke4!('ik')
4
+
5
+ module Cucumber
6
+ class IokeException < StandardError
7
+ end
8
+
9
+ module IkSupport
10
+ class IkLanguage
11
+ def snippet_text(step_keyword, step_name, multiline_arg_class = nil)
12
+ "#{step_keyword}(#/^#{step_name}$/,\n pending\n)\n"
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ begin
2
+ class ::Java::Cuke4dukeInternalJava::JavaAnalyzer
3
+ def snippet_generator
4
+ require 'cucumber/java_support/java_snippet_generator'
5
+ Cucumber::JavaSupport::JavaSnippetGenerator.new
6
+ end
7
+
8
+ Cucumber::ClassSupport::ClassLanguage.add_analyzers(self.new)
9
+ end
10
+ rescue NameError => ignore
11
+ end
@@ -0,0 +1,42 @@
1
+ require 'iconv'
2
+
3
+ module Cucumber
4
+ module JavaSupport
5
+ class JavaSnippetGenerator
6
+ def snippet_text(step_keyword, step_name, multiline_arg_class = nil)
7
+ escaped = Regexp.escape(step_name).gsub('\ ', ' ').gsub('/', '\/')
8
+ escaped = escaped.gsub(PARAM_PATTERN, ESCAPED_PARAM_PATTERN)
9
+ @iconv ||= Iconv.new('ASCII//IGNORE//TRANSLIT', 'UTF-8')
10
+ method_name = @iconv.iconv(step_name).unpack('U*').select{ |cp| cp < 127 }.pack('U*')
11
+ # Terrible hack for what seems to be a strange JRuby bug (1.4)
12
+ # Without this, method_name is the text of the entire feature (???!!)
13
+ method_name = method_name.split("\n")[-1]
14
+ method_name = method_name.gsub(/"|\s/, '_')
15
+ method_name = method_name.gsub(/_+/, '_')
16
+ method_name = method_name.gsub(/^_/, '')
17
+ method_name = method_name.gsub(/(?:^|_)(.)/) { $1.upcase }
18
+ method_name = method_name[0..0].downcase + (method_name[1..-1] || "")
19
+ method_name += "With" + multiline_arg_class.default_arg_name.capitalize if multiline_arg_class
20
+
21
+ n = 0
22
+ args = escaped.scan(ESCAPED_PARAM_PATTERN).map do |a|
23
+ n += 1
24
+ "String arg#{n}"
25
+ end
26
+ args << "cuke4duke.Table #{multiline_arg_class.default_arg_name}" if Cucumber::Ast::Table == multiline_arg_class
27
+ args << "String #{multiline_arg_class.default_arg_name}" if Cucumber::Ast::PyString == multiline_arg_class
28
+ arg_string = args.join(", ")
29
+
30
+ %{@#{step_keyword}("^#{escaped}$")\n} +
31
+ %{@Pending\n} +
32
+ %{public void #{method_name}(#{arg_string}) {\n}}
33
+ end
34
+
35
+ private
36
+
37
+ PARAM_PATTERN = /"([^\"]*)"/
38
+ ESCAPED_PARAM_PATTERN = '\\"([^\\"]*)\\"'
39
+
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,65 @@
1
+ require 'rubygems'
2
+ require 'cucumber'
3
+ require 'spec/autorun'
4
+
5
+ $:.unshift(File.dirname(__FILE__) + '/../..')
6
+ require 'cucumber/java_support/java_snippet_generator'
7
+
8
+ module Cucumber
9
+ module JavaSupport
10
+ describe JavaSnippetGenerator do
11
+ def unindented(s)
12
+ s.split("\n")[1..-2].join("\n").indent(-10)
13
+ end
14
+
15
+ before do
16
+ @generator = JavaSnippetGenerator.new
17
+ end
18
+
19
+ it "should recognise quotes in name and make according regexp" do
20
+ @generator.snippet_text('Given', 'A "first" arg').should == unindented(%{
21
+ @Given("^A \\\"([^\\\"]*)\\\" arg$")
22
+ @Pending
23
+ public void aFirstArg(String arg1) {
24
+ }
25
+ })
26
+ end
27
+
28
+ it "should recognise several quoted words in name and make according regexp and args" do
29
+ @generator.snippet_text('Given', 'Æ "first" and "second" arg').should == unindented(%{
30
+ @Given("^Æ \\\"([^\\\"]*)\\\" and \\\"([^\\\"]*)\\\" arg$")
31
+ @Pending
32
+ public void aEFirstAndSecondArg(String arg1, String arg2) {
33
+ }
34
+ })
35
+ end
36
+
37
+ it "should not use quote group when there are no quotes" do
38
+ @generator.snippet_text('Given', 'A first arg').should == unindented(%{
39
+ @Given("^A first arg$")
40
+ @Pending
41
+ public void aFirstArg() {
42
+ }
43
+ })
44
+ end
45
+
46
+ it "should be helpful with tables" do
47
+ @generator.snippet_text('Given', 'A "first" arg', Cucumber::Ast::Table).should == unindented(%{
48
+ @Given("^A \\\"([^\\\"]*)\\\" arg$")
49
+ @Pending
50
+ public void aFirstArgWithTable(String arg1, cuke4duke.Table table) {
51
+ }
52
+ })
53
+ end
54
+
55
+ it "should be helpful with multiline strings" do
56
+ @generator.snippet_text('Given', 'A "first" arg', Cucumber::Ast::PyString).should == unindented(%{
57
+ @Given("^A \\\"([^\\\"]*)\\\" arg$")
58
+ @Pending
59
+ public void aFirstArgWithString(String arg1, String string) {
60
+ }
61
+ })
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,2 @@
1
+ require 'cucumber/jvm_support/backtrace_filter'
2
+ Cucumber::Ast::StepInvocation::BACKTRACE_FILTER_PATTERNS << /org\/mozilla\/javascript/
@@ -0,0 +1,3 @@
1
+ require 'cuke4duke/language_proxy'
2
+
3
+ Cuke4Duke.cuke4!('js')
@@ -0,0 +1 @@
1
+ Cucumber::Ast::StepInvocation::BACKTRACE_FILTER_PATTERNS << /cuke4duke|org\/jruby|org\/junit|org\/hamcrest|java\/lang|java\.lang|sun\/reflect|sun\.reflect/
@@ -0,0 +1,2 @@
1
+ require 'cucumber/java_support/backtrace_filter'
2
+ Cucumber::Ast::StepInvocation::BACKTRACE_FILTER_PATTERNS << /^\s*scala/
@@ -0,0 +1,11 @@
1
+ begin
2
+ class ::Java::Cuke4dukeInternalScala::ScalaAnalyzer
3
+ def snippet_generator
4
+ require 'cucumber/scala_support/scala_snippet_generator'
5
+ Cucumber::JavaSupport::ScalaSnippetGenerator.new
6
+ end
7
+
8
+ Cucumber::ClassSupport::ClassLanguage.add_analyzers(self.new)
9
+ end
10
+ rescue NameError => ignore
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'iconv'
2
+
3
+ module Cucumber
4
+ module ScalaSupport
5
+ class ScalaSnippetGenerator
6
+ def snippet_text(step_keyword, step_name, multiline_arg_class = nil)
7
+ "Scala snippet... TODO"
8
+ end
9
+ end
10
+ end
11
+ end
data/lib/cuke4duke.rb ADDED
@@ -0,0 +1,24 @@
1
+ require 'rubygems'
2
+ require 'cucumber'
3
+ require 'cuke4duke/version'
4
+ begin
5
+ require "cuke4duke-#{Cuke4Duke::VERSION}.jar"
6
+ rescue LoadError
7
+ require "cuke4duke-#{Cuke4Duke::VERSION.gsub(/\.beta$/, '-SNAPSHOT')}.jar"
8
+ end
9
+ Cucumber::VERSION << " (cuke4duke #{Cuke4Duke::VERSION})"
10
+
11
+ require 'cucumber/formatter/unicode'
12
+
13
+ # Workaround to make the java code have access to the same Ruby
14
+ # interpreter as the one that is used to run this script.
15
+ # org.jruby.Main uses a different instance than what
16
+ # org.jruby.Ruby.getGlobalRuntime() returns. It might be considered
17
+ # a JRuby bug.
18
+ Java.cuke4duke.spi.jruby.JRuby.setRuntime(JRuby.runtime)
19
+
20
+ require 'cuke4duke/step_mother_ext'
21
+ require 'cuke4duke/py_string_ext'
22
+ require 'cuke4duke/table_ext'
23
+ require 'cuke4duke/scenario_ext'
24
+ require 'cuke4duke/step_match_ext'
@@ -0,0 +1,32 @@
1
+ require 'forwardable'
2
+
3
+ module Cuke4Duke
4
+ class << self
5
+ # Defines a Ruby class for +lang+ that will delegate to cuke4duke.
6
+ def cuke4!(lang)
7
+ require "cucumber/#{lang}_support/backtrace_filter"
8
+
9
+ Cucumber.module_eval do
10
+ const_set("#{lang.capitalize}Support", Module.new do
11
+ const_set("#{lang.capitalize}Language", Class.new do
12
+ extend Forwardable
13
+ include Cucumber::LanguageSupport::LanguageMethods
14
+
15
+ def_delegators :@delegate, :load_code_file, :step_matches, :begin_scenario, :end_scenario
16
+
17
+ define_method(:initialize) do |step_mother|
18
+ @delegate = eval("Java.cuke4duke.internal.#{lang}.#{lang.capitalize}Language", binding, __FILE__, __LINE__).new(self, Java.cuke4duke.spi.jruby.JRubyExceptionFactory.new)
19
+ end
20
+
21
+ def alias_adverbs(adverbs)
22
+ end
23
+
24
+ define_method(:snippet_text) do |step_keyword, step_name, multiline_arg_class|
25
+ "YAY A #{lang} SNIPPET: #{step_keyword}, #{step_name}, #{multiline_arg_class}"
26
+ end
27
+ end)
28
+ end)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,7 @@
1
+ module Cucumber
2
+ module Ast
3
+ class PyString
4
+ include Java.cuke4duke.PyString
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Cucumber
2
+ module Ast
3
+ class Scenario
4
+ include Java.cuke4duke.Scenario
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module Cucumber
2
+ class StepMatch
3
+ include Java.cuke4duke.spi.jruby.StepMatch
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Cucumber
2
+ class StepMother
3
+ include Java.cuke4duke.StepMother
4
+ end
5
+ end
@@ -0,0 +1,46 @@
1
+ module Cucumber
2
+ module Ast
3
+ class Table
4
+ include Java.cuke4duke.Table
5
+
6
+ def diffLists(list_list, options={})
7
+ diff!(lists_to_arrays(list_list), opts(options))
8
+ end
9
+
10
+ def diffHashes(map_list, options={})
11
+ diff!(maps_to_hashes(map_list), opts(options))
12
+ end
13
+
14
+ def mapColumn(column, converter)
15
+ map_column!(column) { |cellValue| converter.convertCell(cellValue) }
16
+ end
17
+
18
+ def mapHeaders(mappings)
19
+ map_headers!(Hash[mappings.entrySet.map{|e| [e.key, e.value]}])
20
+ end
21
+
22
+ private
23
+
24
+ def opts(options)
25
+ return options if Hash === options
26
+ opts = {}
27
+ options.each{|k, v| opts[k.to_sym] = v}
28
+ opts
29
+ end
30
+
31
+ def lists_to_arrays(list_list)
32
+ list_list.map{|list| list.map{|e| e}}
33
+ end
34
+
35
+ def maps_to_hashes(map_list)
36
+ map_list.collect{|map| map_to_hash(map)}
37
+ end
38
+
39
+ def map_to_hash(map)
40
+ hash = {}
41
+ map.each{|entry| hash[entry[0]] = entry[1]}
42
+ hash
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,5 @@
1
+ require 'rexml/document'
2
+
3
+ module Cuke4Duke
4
+ VERSION = REXML::XPath.first(REXML::Document.new(IO.read(File.dirname(__FILE__) + '/../../pom.xml')), '//xmlns:project/xmlns:version/text()').to_s.gsub(/-SNAPSHOT$/, '.beta')
5
+ end
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cuke4duke
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 4
8
+ - 0
9
+ version: 0.4.0
10
+ platform: ruby
11
+ authors:
12
+ - "Aslak Helles\xC3\xB8y"
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-10-03 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: cucumber
22
+ version_requirements: &id001 !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ segments:
27
+ - 0
28
+ - 9
29
+ - 1
30
+ version: 0.9.1
31
+ requirement: *id001
32
+ prerelease: false
33
+ type: :runtime
34
+ - !ruby/object:Gem::Dependency
35
+ name: rspec
36
+ version_requirements: &id002 !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ segments:
41
+ - 2
42
+ - 0
43
+ - 0
44
+ - beta
45
+ - 22
46
+ version: 2.0.0.beta.22
47
+ requirement: *id002
48
+ prerelease: false
49
+ type: :development
50
+ - !ruby/object:Gem::Dependency
51
+ name: celerity
52
+ version_requirements: &id003 !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ segments:
57
+ - 0
58
+ - 8
59
+ - 2
60
+ version: 0.8.2
61
+ requirement: *id003
62
+ prerelease: false
63
+ type: :development
64
+ - !ruby/object:Gem::Dependency
65
+ name: jruby-openssl
66
+ version_requirements: &id004 !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ segments:
71
+ - 0
72
+ - 7
73
+ - 1
74
+ version: 0.7.1
75
+ requirement: *id004
76
+ prerelease: false
77
+ type: :development
78
+ - !ruby/object:Gem::Dependency
79
+ name: bundler
80
+ version_requirements: &id005 !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ segments:
85
+ - 1
86
+ - 0
87
+ - 2
88
+ version: 1.0.2
89
+ requirement: *id005
90
+ prerelease: false
91
+ type: :development
92
+ description: Write Cucumber Step Definitions in Java, Scala, Groovy, Rhino Javascript, Clojure or Ioke
93
+ email: cukes@googlegroups.com
94
+ executables:
95
+ - cuke4duke
96
+ extensions: []
97
+
98
+ extra_rdoc_files:
99
+ - LICENCE
100
+ - README.textile
101
+ files:
102
+ - lib/.gitignore
103
+ - lib/cucumber/class_support/backtrace_filter.rb
104
+ - lib/cucumber/class_support/class_language.rb
105
+ - lib/cucumber/clj_support/backtrace_filter.rb
106
+ - lib/cucumber/clj_support/clj_language.rb
107
+ - lib/cucumber/groovy_support/backtrace_filter.rb
108
+ - lib/cucumber/groovy_support/groovy_language.rb
109
+ - lib/cucumber/ik_support/backtrace_filter.rb
110
+ - lib/cucumber/ik_support/ik_language.rb
111
+ - lib/cucumber/java_support/java_analyzer.rb
112
+ - lib/cucumber/java_support/java_snippet_generator.rb
113
+ - lib/cucumber/java_support/java_snippet_generator_spec.rb
114
+ - lib/cucumber/js_support/backtrace_filter.rb
115
+ - lib/cucumber/js_support/js_language.rb
116
+ - lib/cucumber/jvm_support/backtrace_filter.rb
117
+ - lib/cucumber/scala_support/backtrace_filter.rb
118
+ - lib/cucumber/scala_support/scala_analyzer.rb
119
+ - lib/cucumber/scala_support/scala_snippet_generator.rb
120
+ - lib/cuke4duke.rb
121
+ - lib/cuke4duke/language_proxy.rb
122
+ - lib/cuke4duke/py_string_ext.rb
123
+ - lib/cuke4duke/scenario_ext.rb
124
+ - lib/cuke4duke/step_match_ext.rb
125
+ - lib/cuke4duke/step_mother_ext.rb
126
+ - lib/cuke4duke/table_ext.rb
127
+ - lib/cuke4duke/version.rb
128
+ - LICENCE
129
+ - README.textile
130
+ has_rdoc: true
131
+ homepage: http://cukes.info
132
+ licenses: []
133
+
134
+ post_install_message:
135
+ rdoc_options:
136
+ - --charset=UTF-8
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ segments:
144
+ - 0
145
+ version: "0"
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ segments:
151
+ - 0
152
+ version: "0"
153
+ requirements: []
154
+
155
+ rubyforge_project:
156
+ rubygems_version: 1.3.6
157
+ signing_key:
158
+ specification_version: 3
159
+ summary: cuke4duke-0.4.0
160
+ test_files: []
161
+