From ac39f48105fb26089d51be8e50900b641d2e5c04 Mon Sep 17 00:00:00 2001 From: Giles Alexander Date: Sun, 6 Nov 2011 23:17:43 -0600 Subject: [PATCH 1/5] Support specifying step definitions by symbol. If a symbol is passed to a step definition, then that symbol will be sent to the World object. The symbol must therefore refer to a method defined by the World: either in an included module or on the World object. The proc can still be used, but if a symbol is provided the proc will be ignored. Also, support executing the symbol against objects other than the World. If an :on key is provided to the options hash then the proc attached to this will be evaluated against the World, and then the symbol sent to the result of that proc, rather than directly to the World itself. --- lib/cucumber/rb_support/rb_dsl.rb | 23 ++++++++++++------- lib/cucumber/rb_support/rb_language.rb | 4 ++-- lib/cucumber/rb_support/rb_step_definition.rb | 22 ++++++++++++++---- .../rb_support/rb_step_definition_spec.rb | 18 ++++++++++++++- spec/cucumber/step_match_spec.rb | 4 ++-- 5 files changed, 53 insertions(+), 18 deletions(-) diff --git a/lib/cucumber/rb_support/rb_dsl.rb b/lib/cucumber/rb_support/rb_dsl.rb index d6889ca76f..ff0b2b407f 100644 --- a/lib/cucumber/rb_support/rb_dsl.rb +++ b/lib/cucumber/rb_support/rb_dsl.rb @@ -23,8 +23,8 @@ def register_rb_transform(regexp, proc) @rb_language.register_rb_transform(regexp, proc) end - def register_rb_step_definition(regexp, proc) - @rb_language.register_rb_step_definition(regexp, proc) + def register_rb_step_definition(regexp, proc_or_sym, options = {}) + @rb_language.register_rb_step_definition(regexp, proc_or_sym, options) end end @@ -98,12 +98,19 @@ def AfterConfiguration(&proc) # also to the i18n translations whenever a feature of a # new language is loaded. # - # The +&proc+ gets executed in the context of a World - # object, which is defined by #World. A new World - # object is created for each scenario and is shared across - # step definitions within that scenario. - def register_rb_step_definition(regexp, &proc) - RbDsl.register_rb_step_definition(regexp, proc) + # If provided, the +symbol+ is sent to the World object + # as defined by #World. A new World object is created + # for each scenario and is shared across step definitions within + # that scenario. If the +options+ hash contains an :on + # key, the value for this is assumed to be a proc. This proc + # will be executed in the context of the World object + # and then sent the +symbol+. + # + # If no +symbol+ if provided then the +&proc+ gets executed in + # the context of the World object. + def register_rb_step_definition(regexp, symbol = nil, options = {}, &proc) + proc_or_sym = symbol || proc + RbDsl.register_rb_step_definition(regexp, proc_or_sym, options) end end end diff --git a/lib/cucumber/rb_support/rb_language.rb b/lib/cucumber/rb_support/rb_language.rb index bb59050f52..bce857783d 100644 --- a/lib/cucumber/rb_support/rb_language.rb +++ b/lib/cucumber/rb_support/rb_language.rb @@ -124,8 +124,8 @@ def register_rb_transform(regexp, proc) add_transform(RbTransform.new(self, regexp, proc)) end - def register_rb_step_definition(regexp, proc) - step_definition = RbStepDefinition.new(self, regexp, proc) + def register_rb_step_definition(regexp, proc_or_sym, options) + step_definition = RbStepDefinition.new(self, regexp, proc_or_sym, options) @step_definitions << step_definition step_definition end diff --git a/lib/cucumber/rb_support/rb_step_definition.rb b/lib/cucumber/rb_support/rb_step_definition.rb index 72d4e4bf2c..cc2e168a70 100644 --- a/lib/cucumber/rb_support/rb_step_definition.rb +++ b/lib/cucumber/rb_support/rb_step_definition.rb @@ -19,18 +19,25 @@ class RbStepDefinition class MissingProc < StandardError def message - "Step definitions must always have a proc" + "Step definitions must always have a proc or symbol" end end - def initialize(rb_language, regexp, proc) - raise MissingProc if proc.nil? + def initialize(rb_language, regexp, proc_or_sym, options) + raise MissingProc if proc_or_sym.nil? if String === regexp p = Regexp.escape(regexp) p = p.gsub(/\\\$\w+/, '(.*)') # Replace $var with (.*) regexp = Regexp.new("^#{p}$") end - @rb_language, @regexp, @proc = rb_language, regexp, proc + @rb_language, @regexp, @proc = rb_language, regexp, proc_or_sym + if @proc.kind_of? Symbol + @proc = lambda do |*args| + target = options[:on] ? instance_exec(&options[:on]) : self + target.send(proc_or_sym, *args) + end + end + @rb_language.available_step_definition(regexp_source, file_colon_line) end @@ -71,7 +78,12 @@ def backtrace_line end def file_colon_line - @proc.file_colon_line + case @proc + when Proc + @proc.file_colon_line + when Symbol + ":#{@proc}" + end end def file diff --git a/spec/cucumber/rb_support/rb_step_definition_spec.rb b/spec/cucumber/rb_support/rb_step_definition_spec.rb index 362399168b..37ed6f4833 100644 --- a/spec/cucumber/rb_support/rb_step_definition_spec.rb +++ b/spec/cucumber/rb_support/rb_step_definition_spec.rb @@ -44,6 +44,22 @@ module RbSupport $inside.should == 'inside' end + it "should call a method on the world when specified with a symbol" do + rb.current_world.should_receive(:with_symbol) + dsl.Given /With symbol/, :with_symbol + + support_code.step_match("With symbol").invoke(nil) + end + + it "should call a method on a specified object" do + target = double('target') + target.should_receive(:with_symbol) + rb.current_world.stub!(:target).and_return(target) + dsl.Given /With symbol on block/, :with_symbol, :on => lambda { target } + + support_code.step_match("With symbol on block").invoke(nil) + end + it "should raise Undefined when inside step is not defined" do dsl.Given /Outside/ do Given 'Inside' @@ -91,7 +107,7 @@ module RbSupport end it "should have a JSON representation of the signature" do - RbStepDefinition.new(rb, /I CAN HAZ (\d+) CUKES/i, lambda{}).to_hash.should == {'source' => "I CAN HAZ (\\d+) CUKES", 'flags' => 'i'} + RbStepDefinition.new(rb, /I CAN HAZ (\d+) CUKES/i, lambda{}, {}).to_hash.should == {'source' => "I CAN HAZ (\\d+) CUKES", 'flags' => 'i'} end end end diff --git a/spec/cucumber/step_match_spec.rb b/spec/cucumber/step_match_spec.rb index a6c24fe314..fdfacf4ae9 100644 --- a/spec/cucumber/step_match_spec.rb +++ b/spec/cucumber/step_match_spec.rb @@ -12,7 +12,7 @@ module Cucumber end def stepdef(regexp) - RbSupport::RbStepDefinition.new(@rb_language, regexp, lambda{}) + RbSupport::RbStepDefinition.new(@rb_language, regexp, lambda{}, {}) end def step_match(regexp, name) @@ -66,4 +66,4 @@ def step_match(regexp, name) m.format_args("%s").should == "running 5 times 10 meters" end end -end \ No newline at end of file +end From 69b6c7816d8dd9ca057e0f74885fcb0bb812bdde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aslak=20Helles=C3=B8y?= Date: Sun, 30 Oct 2011 21:47:23 +0000 Subject: [PATCH 2/5] Release 1.1.1 --- Gemfile.lock | 67 ++--- History.md | 16 ++ cucumber.gemspec | 22 +- features/json_formatter.feature | 262 +++++++++--------- legacy_features/language_help.feature | 4 +- .../formatter/gherkin_formatter_adapter.rb | 4 + lib/cucumber/formatter/json.rb | 12 - lib/cucumber/platform.rb | 2 +- spec/cucumber/ast/scenario_outline_spec.rb | 3 +- spec/cucumber/cli/main_spec.rb | 2 +- 10 files changed, 202 insertions(+), 192 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index f57c29c042..ec3a29cd5d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,10 +1,10 @@ PATH remote: . specs: - cucumber (1.1.0) + cucumber (1.1.1) builder (>= 2.1.2) diff-lcs (>= 1.1.2) - gherkin (~> 2.5.0) + gherkin (~> 2.6.0) json (>= 1.4.6) term-ansicolor (>= 1.0.6) @@ -30,54 +30,57 @@ GEM childprocess (0.2.2) ffi (~> 1.0.6) diff-lcs (1.1.3) - ffi (1.0.9) - gherkin (2.5.0) + ffi (1.0.10) + gherkin (2.6.0) json (>= 1.4.6) - innate (2011.04) + innate (2011.10) rack (>= 1.1.0) json (1.6.1) json_pure (1.6.1) - mime-types (1.16) + mime-types (1.17.2) multi_json (1.0.3) nokogiri (1.5.0) prawn (0.8.4) - prawn-core (< 0.9, >= 0.8.4) - prawn-layout (< 0.9, >= 0.8.4) - prawn-security (< 0.9, >= 0.8.4) + prawn-core (>= 0.8.4, < 0.9) + prawn-layout (>= 0.8.4, < 0.9) + prawn-security (>= 0.8.4, < 0.9) prawn-core (0.8.4) prawn-layout (0.8.4) prawn-security (0.8.4) - rack (1.3.3) + rack (1.3.5) + rack-protection (1.1.4) + rack rack-test (0.6.1) rack (>= 1.0) - rake (0.9.2) - ramaze (2011.07.25) + rake (0.9.2.2) + ramaze (2011.10.23) innate (>= 2010.03) rdiscount (1.6.8) - rspec (2.6.0) - rspec-core (~> 2.6.0) - rspec-expectations (~> 2.6.0) - rspec-mocks (~> 2.6.0) - rspec-core (2.6.4) - rspec-expectations (2.6.0) + rspec (2.7.0) + rspec-core (~> 2.7.0) + rspec-expectations (~> 2.7.0) + rspec-mocks (~> 2.7.0) + rspec-core (2.7.1) + rspec-expectations (2.7.0) diff-lcs (~> 1.1.2) - rspec-mocks (2.6.0) + rspec-mocks (2.7.0) rubyzip (0.9.4) - selenium-webdriver (2.6.0) + selenium-webdriver (2.8.0) childprocess (>= 0.2.1) ffi (>= 1.0.7) json_pure rubyzip - simplecov (0.5.3) + simplecov (0.5.4) multi_json (~> 1.0.3) simplecov-html (~> 0.5.3) simplecov-html (0.5.3) - sinatra (1.2.6) - rack (~> 1.1) - tilt (< 2.0, >= 1.2.2) + sinatra (1.3.1) + rack (~> 1.3, >= 1.3.4) + rack-protection (~> 1.1, >= 1.1.2) + tilt (~> 1.3, >= 1.3.3) spork (0.9.0.rc9) syntax (1.0.0) - term-ansicolor (1.0.6) + term-ansicolor (1.0.7) tilt (1.3.3) webrat (0.7.3) nokogiri (>= 1.2.0) @@ -85,7 +88,7 @@ GEM rack-test (>= 0.5.3) xpath (0.1.4) nokogiri (~> 1.3) - yard (0.7.2) + yard (0.7.3) PLATFORMS ruby @@ -93,19 +96,19 @@ PLATFORMS DEPENDENCIES aruba (~> 0.4.6) bcat (~> 0.6.1) - capybara (>= 1.1.0) + capybara (>= 1.1.1) cucumber! nokogiri (>= 1.5.0) prawn (~> 0.8.4) prawn-layout (~> 0.8.4) - rack-test (>= 0.5.7) + rack-test (>= 0.6.1) rake (>= 0.9.2) ramaze rdiscount (~> 1.6.8) - rspec (>= 2.6.0) - simplecov (>= 0.4.2) - sinatra (>= 1.2.6) + rspec (>= 2.7.0) + simplecov (>= 0.5.4) + sinatra (>= 1.3.1) spork (>= 0.9.0.rc9) syntax (>= 1.0.0) webrat (>= 0.7.3) - yard (~> 0.7.2) + yard (~> 0.7.3) diff --git a/History.md b/History.md index a820283596..f21f341c21 100644 --- a/History.md +++ b/History.md @@ -1,3 +1,19 @@ +## [v1.1.1](https://github.com/cucumber/cucumber/compare/v1.1.0...v1.1.1) + +### Changed features + +The JSON formatter output has changed slightly. Old format: + + { + features: [feature here] + } + +New format: + + [feature here] + +Also see [Gherkin 2.6.0 History](https://github.com/cucumber/gherkin/blob/master/History.md) for info about new `id` and `uri` elements in the JSON. + ## [v1.1.0](https://github.com/cucumber/cucumber/compare/v1.0.6...v1.1.0) ### Changed features diff --git a/cucumber.gemspec b/cucumber.gemspec index d68f4ee031..faa1dfc15c 100644 --- a/cucumber.gemspec +++ b/cucumber.gemspec @@ -23,33 +23,33 @@ for important information about this release. Happy cuking! } - s.add_dependency 'gherkin', '~> 2.5.0' - s.add_dependency 'term-ansicolor', '>= 1.0.6' - s.add_dependency 'builder', '>= 2.1.2' - s.add_dependency 'diff-lcs', '>= 1.1.2' - s.add_dependency 'json', '>= 1.4.6' + s.add_runtime_dependency 'gherkin', '~> 2.6.0' + s.add_runtime_dependency 'term-ansicolor', '>= 1.0.6' + s.add_runtime_dependency 'builder', '>= 2.1.2' + s.add_runtime_dependency 'diff-lcs', '>= 1.1.2' + s.add_runtime_dependency 'json', '>= 1.4.6' s.add_development_dependency 'aruba', '~> 0.4.6' s.add_development_dependency 'rake', '>= 0.9.2' - s.add_development_dependency 'rspec', '>= 2.6.0' + s.add_development_dependency 'rspec', '>= 2.7.0' s.add_development_dependency 'nokogiri', '>= 1.5.0' s.add_development_dependency 'prawn', '~> 0.8.4' s.add_development_dependency 'prawn-layout', '~> 0.8.4' s.add_development_dependency 'syntax', '>= 1.0.0' s.add_development_dependency 'spork', '>= 0.9.0.rc9' - s.add_development_dependency 'simplecov', '>= 0.4.2' + s.add_development_dependency 'simplecov', '>= 0.5.4' # For Documentation: - s.add_development_dependency('yard', '~> 0.7.2') + s.add_development_dependency('yard', '~> 0.7.3') s.add_development_dependency('rdiscount', '~> 1.6.8') s.add_development_dependency('bcat', '~> 0.6.1') # Needed for examples (rake examples) s.add_development_dependency 'ramaze' - s.add_development_dependency 'rack-test', '>= 0.5.7' + s.add_development_dependency 'rack-test', '>= 0.6.1' s.add_development_dependency 'webrat', '>= 0.7.3' - s.add_development_dependency 'sinatra', '>= 1.2.6' - s.add_development_dependency 'capybara', '>= 1.1.0' + s.add_development_dependency 'sinatra', '>= 1.3.1' + s.add_development_dependency 'capybara', '>= 1.1.1' s.rubygems_version = ">= 1.6.1" s.files = `git ls-files`.split("\n") diff --git a/features/json_formatter.feature b/features/json_formatter.feature index d8a84c30ec..27aaf649bd 100644 --- a/features/json_formatter.feature +++ b/features/json_formatter.feature @@ -60,85 +60,83 @@ Feature: JSON output formatter """ - Scenario: one feature, one passing scenario, one failing scenario - When I run cucumber "--format json features/one_passing_one_failing.feature" - Then the output should match /^\{"features":\[/ - Scenario: one feature, one passing scenario, one failing scenario When I run cucumber "--format json features/one_passing_one_failing.feature" Then it should fail with JSON: """ - { - "features": [ - { - "keyword": "Feature", - "name": "One passing scenario, one failing scenario", - "line": 2, - "description": "", - "tags": [ - { - "name": "@a", - "line": 1 - } - ], - "elements": [ - { - "keyword": "Scenario", - "name": "Passing", - "line": 5, - "description": "", - "tags": [ - { - "name": "@b", - "line": 4 - } - ], - "type": "scenario", - "steps": [ - { - "keyword": "Given ", - "name": "a passing step", - "line": 6, - "match": { - "location": "features/step_definitions/steps.rb:1" - }, - "result": { - "status": "passed" - } - } - ] - }, - { - "keyword": "Scenario", - "name": "Failing", - "line": 9, - "description": "", - "tags": [ - { - "name": "@c", - "line": 8 + [ + { + "uri": "features/one_passing_one_failing.feature", + "keyword": "Feature", + "id": "one-passing-scenario,-one-failing-scenario", + "name": "One passing scenario, one failing scenario", + "line": 2, + "description": "", + "tags": [ + { + "name": "@a", + "line": 1 + } + ], + "elements": [ + { + "keyword": "Scenario", + "id": "one-passing-scenario,-one-failing-scenario;passing", + "name": "Passing", + "line": 5, + "description": "", + "tags": [ + { + "name": "@b", + "line": 4 + } + ], + "type": "scenario", + "steps": [ + { + "keyword": "Given ", + "name": "a passing step", + "line": 6, + "match": { + "location": "features/step_definitions/steps.rb:1" + }, + "result": { + "status": "passed" } - ], - "type": "scenario", - "steps": [ - { - "keyword": "Given ", - "name": "a failing step", - "line": 10, - "match": { - "location": "features/step_definitions/steps.rb:5" - }, - "result": { - "status": "failed", - "error_message": " (RuntimeError)\n./features/step_definitions/steps.rb:6:in `/a failing step/'\nfeatures/one_passing_one_failing.feature:10:in `Given a failing step'" - } + } + ] + }, + { + "keyword": "Scenario", + "id": "one-passing-scenario,-one-failing-scenario;failing", + "name": "Failing", + "line": 9, + "description": "", + "tags": [ + { + "name": "@c", + "line": 8 + } + ], + "type": "scenario", + "steps": [ + { + "keyword": "Given ", + "name": "a failing step", + "line": 10, + "match": { + "location": "features/step_definitions/steps.rb:5" + }, + "result": { + "status": "failed", + "error_message": " (RuntimeError)\n./features/step_definitions/steps.rb:6:in `/a failing step/'\nfeatures/one_passing_one_failing.feature:10:in `Given a failing step'" } - ] - } - ] - } - ] - } + } + ] + } + ] + } + ] """ @@ -162,59 +160,17 @@ Feature: JSON output formatter When I run cucumber "--format json features/doc_string.feature" Then it should fail with JSON: """ - { - "features": [ - { - "keyword": "Feature", - "name": "A DocString feature", - "line": 1, - "description": "", - "elements": [ - { - "keyword": "Scenario", - "name": "", - "line": 3, - "description": "", - "type": "scenario", - "steps": [ - { - "keyword": "Then ", - "name": "I should fail with", - "line": 4, - "doc_string": { - "content_type": "", - "value": "a string", - "line": 5 - }, - "match": { - "location": "features/step_definitions/doc_string_steps.rb:1" - }, - "result": { - "status": "failed", - "error_message": "a string (RuntimeError)\n./features/step_definitions/doc_string_steps.rb:2:in `/I should fail with/'\nfeatures/doc_string.feature:4:in `Then I should fail with'" - } - } - ] - } - ] - } - ] - } - """ - - Scenario: embedding screenshot - When I run cucumber "-b --format json features/embed.feature" - Then it should pass with JSON: - """ - { - "features": [ + [ { + "id": "a-docstring-feature", + "uri": "features/doc_string.feature", "keyword": "Feature", - "name": "A screenshot feature", + "name": "A DocString feature", "line": 1, "description": "", "elements": [ { + "id": "a-docstring-feature;", "keyword": "Scenario", "name": "", "line": 3, @@ -222,20 +178,20 @@ Feature: JSON output formatter "type": "scenario", "steps": [ { - "keyword": "Given ", - "name": "I embed a screenshot", + "keyword": "Then ", + "name": "I should fail with", "line": 4, - "embeddings": [ - { - "mime_type": "image/png", - "data": "Zm9v" - } - ], + "doc_string": { + "content_type": "", + "value": "a string", + "line": 5 + }, "match": { - "location": "features/step_definitions/steps.rb:29" + "location": "features/step_definitions/doc_string_steps.rb:1" }, "result": { - "status": "passed" + "status": "failed", + "error_message": "a string (RuntimeError)\n./features/step_definitions/doc_string_steps.rb:2:in `/I should fail with/'\nfeatures/doc_string.feature:4:in `Then I should fail with'" } } ] @@ -243,6 +199,50 @@ Feature: JSON output formatter ] } ] - } + """ + + Scenario: embedding screenshot + When I run cucumber "-b --format json features/embed.feature" + Then it should pass with JSON: + """ + [ + { + "uri": "features/embed.feature", + "id": "a-screenshot-feature", + "keyword": "Feature", + "name": "A screenshot feature", + "line": 1, + "description": "", + "elements": [ + { + "id": "a-screenshot-feature;", + "keyword": "Scenario", + "name": "", + "line": 3, + "description": "", + "type": "scenario", + "steps": [ + { + "keyword": "Given ", + "name": "I embed a screenshot", + "line": 4, + "embeddings": [ + { + "mime_type": "image/png", + "data": "Zm9v" + } + ], + "match": { + "location": "features/step_definitions/steps.rb:29" + }, + "result": { + "status": "passed" + } + } + ] + } + ] + } + ] """ diff --git a/legacy_features/language_help.feature b/legacy_features/language_help.feature index b73e52bb8d..a0429bc8cd 100644 --- a/legacy_features/language_help.feature +++ b/legacy_features/language_help.feature @@ -12,12 +12,12 @@ Feature: Language help | scenario | "Cenário", "Cenario" | | scenario_outline | "Esquema do Cenário", "Esquema do Cenario" | | examples | "Exemplos" | - | given | "* ", "Dado " | + | given | "* ", "Dado ", "Dada ", "Dados ", "Dadas " | | when | "* ", "Quando " | | then | "* ", "Então ", "Entao " | | and | "* ", "E " | | but | "* ", "Mas " | - | given (code) | "Dado" | + | given (code) | "Dado", "Dada", "Dados", "Dadas" | | when (code) | "Quando" | | then (code) | "Então", "Entao" | | and (code) | "E" | diff --git a/lib/cucumber/formatter/gherkin_formatter_adapter.rb b/lib/cucumber/formatter/gherkin_formatter_adapter.rb index c6ee2cd107..85b73600f4 100644 --- a/lib/cucumber/formatter/gherkin_formatter_adapter.rb +++ b/lib/cucumber/formatter/gherkin_formatter_adapter.rb @@ -71,6 +71,10 @@ def after_feature(feature) @gf.eof end + def after_features(features) + @gf.close + end + def embed(file, mime_type, label) data = File.read(file) if defined?(JRUBY_VERSION) diff --git a/lib/cucumber/formatter/json.rb b/lib/cucumber/formatter/json.rb index 8e409e78bd..8ac9b721b2 100644 --- a/lib/cucumber/formatter/json.rb +++ b/lib/cucumber/formatter/json.rb @@ -11,20 +11,8 @@ class Json < GherkinFormatterAdapter def initialize(step_mother, io, options) @io = ensure_io(io, "json") - @io.write('{"features":[') super(Gherkin::Formatter::JSONFormatter.new(@io), false) end - - def before_feature(feature) - super - @io.write(',') if @one - @one = true - end - - def after_features(features) - @io.write(']}') - @io.flush - end end end end diff --git a/lib/cucumber/platform.rb b/lib/cucumber/platform.rb index 7fea668a79..74384026a4 100644 --- a/lib/cucumber/platform.rb +++ b/lib/cucumber/platform.rb @@ -4,7 +4,7 @@ module Cucumber unless defined?(Cucumber::VERSION) - VERSION = '1.1.0' + VERSION = '1.1.1' BINARY = File.expand_path(File.dirname(__FILE__) + '/../../bin/cucumber') LIBDIR = File.expand_path(File.dirname(__FILE__) + '/../../lib') JRUBY = defined?(JRUBY_VERSION) diff --git a/spec/cucumber/ast/scenario_outline_spec.rb b/spec/cucumber/ast/scenario_outline_spec.rb index a07bc1f475..11e272abe4 100644 --- a/spec/cucumber/ast/scenario_outline_spec.rb +++ b/spec/cucumber/ast/scenario_outline_spec.rb @@ -52,10 +52,9 @@ module Ast %w{20 6 14} ] ], - Gherkin::Formatter::Model::Examples.new(nil, nil, nil, nil, nil, nil, nil) + Gherkin::Formatter::Model::Examples.new(nil, nil, nil, nil, nil, nil, nil, nil) ] ] - ) end diff --git a/spec/cucumber/cli/main_spec.rb b/spec/cucumber/cli/main_spec.rb index df65480245..9a9333be36 100644 --- a/spec/cucumber/cli/main_spec.rb +++ b/spec/cucumber/cli/main_spec.rb @@ -47,7 +47,7 @@ def do_execute before(:each) do b = Cucumber::Parser::GherkinBuilder.new - @empty_feature = b.feature(Gherkin::Formatter::Model::Feature.new([], [], "Feature", "Foo", "", 99)) + @empty_feature = b.feature(Gherkin::Formatter::Model::Feature.new([], [], "Feature", "Foo", "", 99, "")) end it "should show feature files parsed" do From dd850cfcb659d794524061b742b427b5b197c55d Mon Sep 17 00:00:00 2001 From: Matt Wynne Date: Mon, 17 Oct 2011 00:13:50 +0100 Subject: [PATCH 3/5] Deprecate i18n methods in RbWorld #68 --- History.md | 4 ++ features/nested_steps.feature | 60 +++++++++++++++++++ .../call_steps_from_stepdefs.feature | 2 +- .../step_definitions/cucumber_steps.rb | 2 +- lib/cucumber/rb_support/rb_world.rb | 10 +++- .../rb_support/rb_step_definition_spec.rb | 6 +- 6 files changed, 76 insertions(+), 8 deletions(-) create mode 100644 features/nested_steps.feature diff --git a/History.md b/History.md index f21f341c21..489c0c6d66 100644 --- a/History.md +++ b/History.md @@ -13,6 +13,10 @@ New format: [feature here] Also see [Gherkin 2.6.0 History](https://github.com/cucumber/gherkin/blob/master/History.md) for info about new `id` and `uri` elements in the JSON. +## In Git + +### Changed features +* Deprecated i18n methods in World, and added a new #step method to use instead. ([#68](https://github.com/cucumber/cucumber/issues/68) Matt Wynne) ## [v1.1.0](https://github.com/cucumber/cucumber/compare/v1.0.6...v1.1.0) diff --git a/features/nested_steps.feature b/features/nested_steps.feature new file mode 100644 index 0000000000..09c98f3989 --- /dev/null +++ b/features/nested_steps.feature @@ -0,0 +1,60 @@ +Feature: Nested Steps + + + Background: + Given a scenario with a step that looks like this: + """gherkin + Given two turtles + """ + And a step definition that looks like this: + """ruby + Given /a turtle/ do + puts "turtle!" + end + """ + + Scenario: Use #steps to call several steps at once + Given a step definition that looks like this: + """ruby + Given /two turtles/ do + steps %{ + Given a turtle + And a turtle + } + end + """ + When I run the feature with the progress formatter + Then the output should contain: + """ + turtle! + + turtle! + + """ + + Scenario: Use #step to call a single step + Given a step definition that looks like this: + """ruby + Given /two turtles/ do + step "a turtle" + step "a turtle" + end + """ + When I run the feature with the progress formatter + Then the output should contain: + """ + turtle! + + turtle! + + """ + + Scenario: Use deprecated i18n methods + Given a step definition that looks like this: + """ruby + Given /two turtles/ do + Given "a turtle" + end + """ + When I run the feature with the progress formatter + Then the output should contain "WARNING" diff --git a/legacy_features/call_steps_from_stepdefs.feature b/legacy_features/call_steps_from_stepdefs.feature index df93267188..b096d3d6b4 100644 --- a/legacy_features/call_steps_from_stepdefs.feature +++ b/legacy_features/call_steps_from_stepdefs.feature @@ -46,7 +46,7 @@ Feature: http://gist.github.com/221223 end Given /^I use keyword to call a multiline string with (.*)$/ do |s| x=1 - Given 'a multiline string:', "Hello\n#{s}" + step 'a multiline string:', "Hello\n#{s}" end Given /^I call a table with (.*)$/ do |s| x=1 diff --git a/legacy_features/step_definitions/cucumber_steps.rb b/legacy_features/step_definitions/cucumber_steps.rb index 206578e6bf..6d5738d223 100644 --- a/legacy_features/step_definitions/cucumber_steps.rb +++ b/legacy_features/step_definitions/cucumber_steps.rb @@ -75,7 +75,7 @@ unless combined_output.index(output) combined_output.should == output end - Then("it should #{success}") + step("it should #{success}") end Then /^the output should contain "([^"]*)"$/ do |text| diff --git a/lib/cucumber/rb_support/rb_world.rb b/lib/cucumber/rb_support/rb_world.rb index a89d81e8b2..f8bfa3cd1a 100644 --- a/lib/cucumber/rb_support/rb_world.rb +++ b/lib/cucumber/rb_support/rb_world.rb @@ -17,12 +17,16 @@ def Transform(arg) rb = @__cucumber_step_mother.load_programming_language('rb') rb.execute_transforms([arg]).first end - + attr_writer :__cucumber_step_mother, :__natural_language - # Call a step from within a step definition. This method is aliased to - # the same i18n as RbDsl. def __cucumber_invoke(name, multiline_argument=nil) #:nodoc: + STDERR.puts failed + "WARNING: i18n methods within step definitions are deprecated. Use #step instead:" + caller[0] + reset + @__cucumber_step_mother.invoke(name, multiline_argument) + end + + # Invoke a single step. + def step(name, multiline_argument=nil) @__cucumber_step_mother.invoke(name, multiline_argument) end diff --git a/spec/cucumber/rb_support/rb_step_definition_spec.rb b/spec/cucumber/rb_support/rb_step_definition_spec.rb index 37ed6f4833..2825c50c22 100644 --- a/spec/cucumber/rb_support/rb_step_definition_spec.rb +++ b/spec/cucumber/rb_support/rb_step_definition_spec.rb @@ -22,7 +22,7 @@ module RbSupport it "should allow calling of other steps" do dsl.Given /Outside/ do - Given "Inside" + step "Inside" end dsl.Given /Inside/ do $inside = true @@ -34,7 +34,7 @@ module RbSupport it "should allow calling of other steps with inline arg" do dsl.Given /Outside/ do - Given "Inside", Cucumber::Ast::Table.new([['inside']]) + step "Inside", Cucumber::Ast::Table.new([['inside']]) end dsl.Given /Inside/ do |table| $inside = table.raw[0][0] @@ -62,7 +62,7 @@ module RbSupport it "should raise Undefined when inside step is not defined" do dsl.Given /Outside/ do - Given 'Inside' + step 'Inside' end lambda do From dbd6ff7a4b921b4f49b55e9ac57626c469f2a42e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aslak=20Helles=C3=B8y?= Date: Fri, 4 Nov 2011 00:18:53 +0000 Subject: [PATCH 4/5] Break long lines. Remove Gemfile.lock. --- .gitignore | 1 + Gemfile.lock | 114 ------------------ legacy_features/default_snippets.feature | 5 +- .../snippets_when_using_star_keyword.feature | 5 +- lib/cucumber/formatter/console.rb | 5 +- 5 files changed, 10 insertions(+), 120 deletions(-) delete mode 100644 Gemfile.lock diff --git a/.gitignore b/.gitignore index d85dd59457..3d135bac25 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,4 @@ rerun.txt .sass-cache doc/ *.tgz +Gemfile.lock diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index ec3a29cd5d..0000000000 --- a/Gemfile.lock +++ /dev/null @@ -1,114 +0,0 @@ -PATH - remote: . - specs: - cucumber (1.1.1) - builder (>= 2.1.2) - diff-lcs (>= 1.1.2) - gherkin (~> 2.6.0) - json (>= 1.4.6) - term-ansicolor (>= 1.0.6) - -GEM - remote: http://rubygems.org/ - specs: - aruba (0.4.6) - bcat (>= 0.6.1) - childprocess (>= 0.2.0) - cucumber (>= 1.0.2) - rdiscount (>= 1.6.8) - rspec (>= 2.6.0) - bcat (0.6.2) - rack (~> 1.0) - builder (3.0.0) - capybara (1.1.1) - mime-types (>= 1.16) - nokogiri (>= 1.3.3) - rack (>= 1.0.0) - rack-test (>= 0.5.4) - selenium-webdriver (~> 2.0) - xpath (~> 0.1.4) - childprocess (0.2.2) - ffi (~> 1.0.6) - diff-lcs (1.1.3) - ffi (1.0.10) - gherkin (2.6.0) - json (>= 1.4.6) - innate (2011.10) - rack (>= 1.1.0) - json (1.6.1) - json_pure (1.6.1) - mime-types (1.17.2) - multi_json (1.0.3) - nokogiri (1.5.0) - prawn (0.8.4) - prawn-core (>= 0.8.4, < 0.9) - prawn-layout (>= 0.8.4, < 0.9) - prawn-security (>= 0.8.4, < 0.9) - prawn-core (0.8.4) - prawn-layout (0.8.4) - prawn-security (0.8.4) - rack (1.3.5) - rack-protection (1.1.4) - rack - rack-test (0.6.1) - rack (>= 1.0) - rake (0.9.2.2) - ramaze (2011.10.23) - innate (>= 2010.03) - rdiscount (1.6.8) - rspec (2.7.0) - rspec-core (~> 2.7.0) - rspec-expectations (~> 2.7.0) - rspec-mocks (~> 2.7.0) - rspec-core (2.7.1) - rspec-expectations (2.7.0) - diff-lcs (~> 1.1.2) - rspec-mocks (2.7.0) - rubyzip (0.9.4) - selenium-webdriver (2.8.0) - childprocess (>= 0.2.1) - ffi (>= 1.0.7) - json_pure - rubyzip - simplecov (0.5.4) - multi_json (~> 1.0.3) - simplecov-html (~> 0.5.3) - simplecov-html (0.5.3) - sinatra (1.3.1) - rack (~> 1.3, >= 1.3.4) - rack-protection (~> 1.1, >= 1.1.2) - tilt (~> 1.3, >= 1.3.3) - spork (0.9.0.rc9) - syntax (1.0.0) - term-ansicolor (1.0.7) - tilt (1.3.3) - webrat (0.7.3) - nokogiri (>= 1.2.0) - rack (>= 1.0) - rack-test (>= 0.5.3) - xpath (0.1.4) - nokogiri (~> 1.3) - yard (0.7.3) - -PLATFORMS - ruby - -DEPENDENCIES - aruba (~> 0.4.6) - bcat (~> 0.6.1) - capybara (>= 1.1.1) - cucumber! - nokogiri (>= 1.5.0) - prawn (~> 0.8.4) - prawn-layout (~> 0.8.4) - rack-test (>= 0.6.1) - rake (>= 0.9.2) - ramaze - rdiscount (~> 1.6.8) - rspec (>= 2.7.0) - simplecov (>= 0.5.4) - sinatra (>= 1.3.1) - spork (>= 0.9.0.rc9) - syntax (>= 1.0.0) - webrat (>= 0.7.3) - yard (~> 0.7.3) diff --git a/legacy_features/default_snippets.feature b/legacy_features/default_snippets.feature index 1ed8fc6654..c40027f058 100644 --- a/legacy_features/default_snippets.feature +++ b/legacy_features/default_snippets.feature @@ -34,8 +34,9 @@ Feature: Print snippets pending # express the regexp above with the code you wish you had end - If you want snippets in a different programming language, just make sure a file - with the appropriate file extension exists where cucumber looks for step definitions. + If you want snippets in a different programming language, + just make sure a file with the appropriate file extension + exists where cucumber looks for step definitions. """ diff --git a/legacy_features/snippets_when_using_star_keyword.feature b/legacy_features/snippets_when_using_star_keyword.feature index 5c151123c3..ee908641d5 100644 --- a/legacy_features/snippets_when_using_star_keyword.feature +++ b/legacy_features/snippets_when_using_star_keyword.feature @@ -29,8 +29,9 @@ Feature: Use * keywords and still get snippets pending # express the regexp above with the code you wish you had end - If you want snippets in a different programming language, just make sure a file - with the appropriate file extension exists where cucumber looks for step definitions. + If you want snippets in a different programming language, + just make sure a file with the appropriate file extension + exists where cucumber looks for step definitions. """ diff --git a/lib/cucumber/formatter/console.rb b/lib/cucumber/formatter/console.rb index a4d3a742fc..c83700fbfc 100644 --- a/lib/cucumber/formatter/console.rb +++ b/lib/cucumber/formatter/console.rb @@ -114,8 +114,9 @@ def print_snippets(options) @io.puts format_string(text, :undefined) if unknown_programming_language - @io.puts format_string("\nIf you want snippets in a different programming language, just make sure a file\n" + - "with the appropriate file extension exists where cucumber looks for step definitions.", :failed) + @io.puts format_string("\nIf you want snippets in a different programming language,\n" + + "just make sure a file with the appropriate file extension\n" + + "exists where cucumber looks for step definitions.", :failed) end @io.puts From feef68a5e9be2822cca8dfeaf71b3c62c115853f Mon Sep 17 00:00:00 2001 From: Jani Patokallio Date: Fri, 4 Nov 2011 20:44:19 +1100 Subject: [PATCH 5/5] Less user-hostile error message --- lib/cucumber/rb_support/rb_world.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cucumber/rb_support/rb_world.rb b/lib/cucumber/rb_support/rb_world.rb index f8bfa3cd1a..9cbc09710f 100644 --- a/lib/cucumber/rb_support/rb_world.rb +++ b/lib/cucumber/rb_support/rb_world.rb @@ -21,7 +21,7 @@ def Transform(arg) attr_writer :__cucumber_step_mother, :__natural_language def __cucumber_invoke(name, multiline_argument=nil) #:nodoc: - STDERR.puts failed + "WARNING: i18n methods within step definitions are deprecated. Use #step instead:" + caller[0] + reset + STDERR.puts failed + "WARNING: Using 'Given/When/Then' in step definitions is deprecated, use 'step' to call other steps instead:" + caller[0] + reset @__cucumber_step_mother.invoke(name, multiline_argument) end