Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/josephwilk/cucumber
Browse files Browse the repository at this point in the history
  • Loading branch information
aslakhellesoy committed Apr 26, 2009
2 parents 9e34bd9 + 4b2f049 commit 5eda40b
Show file tree
Hide file tree
Showing 14 changed files with 184 additions and 55 deletions.
3 changes: 3 additions & 0 deletions History.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ now supports 32(!!) languages.
* Fixed incorrect colours in pretty formatter's table headers for outline tables (Aslak Hellesøy)
* Exceptions from steps called within hooks are now reraised. (#294 Ben Mabey)

=== Removed/changed features
* --scenario handle has been removed and replaced with --name which supports partial matches, regexp special characters, running named backgrounds (#295 Joseph Wilk)

== 0.3.0 2009-04-14

This release has some minor changes to the APIs, but big enough that a new major release is in order.
Expand Down
22 changes: 22 additions & 0 deletions examples/self_test/features/search_sample.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Feature: search examples

Background: Hantu Pisang background match
Given passing without a table

Scenario: should match Hantu Pisang
Given passing without a table

Scenario: Ignore me
Given failing without a table

Scenario Outline: Ignore me
Given <state> without a table
Examples:
|state|
|failing|

Scenario Outline: Hantu Pisang match
Given <state> without a table
Examples:
|state|
|passing|
70 changes: 58 additions & 12 deletions features/cucumber_cli.feature
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,31 @@ Feature: Cucumber command line
hello
\"\"\"
Feature: search examples
Background: Hantu Pisang background match
Given passing without a table
Scenario: should match Hantu Pisang
Given passing without a table
Scenario: Ignore me
Given failing without a table
Scenario Outline: Ignore me
Given <state> without a table
Examples:
| state |
| failing |
Scenario Outline: Hantu Pisang match
Given <state> without a table
Examples:
| state |
| passing |
Feature: undefined multiline args
Scenario: pystring
Expand All @@ -272,8 +297,8 @@ Feature: Cucumber command line
| table |
| example |
17 scenarios
18 skipped steps
21 scenarios
26 skipped steps
9 undefined steps
"""
Expand Down Expand Up @@ -304,24 +329,45 @@ Feature: Cucumber command line
"""

Scenario: Run scenario specified by name using --scenario
When I run cucumber --scenario Passing -q features
Scenario: Run feature elements which matches a name using --name
When I run cucumber --name Pisang -q features/
Then it should pass with
"""
@one
Feature: Sample
Feature: search examples
@three
Scenario: Passing
Given passing
| a | b |
| c | d |
Background: Hantu Pisang background match
Given passing without a table
1 scenario
Scenario: should match Hantu Pisang
Given passing without a table
Scenario Outline: Hantu Pisang match
Given <state> without a table
Examples:
| state |
| passing |
2 scenarios
4 passed steps
"""

Scenario: Run a single background which matches a name using --name
When I run cucumber --name 'Hantu Pisang background' -q features/
Then it should pass with
"""
Feature: search examples
Background: Hantu Pisang background match
Given passing without a table
0 scenarios
1 passed step
"""


Scenario: Run with a tag that exists on 2 scenarios
When I run cucumber -q features --tags three
Then it should pass with
Expand Down
2 changes: 1 addition & 1 deletion features/cucumber_cli_outlines.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Feature: Cucumber command line
Developers should be able to execute requirements as tests

Scenario: Run scenario outline with filtering on outline name
When I run cucumber -q features --scenario "Test state"
When I run cucumber -q features --name "Test state"
Then it should fail with
"""
Feature: Outline Sample
Expand Down
5 changes: 5 additions & 0 deletions features/usage.feature
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@ Feature: Cucumber command line
Given <state> without a table # features/multiline_name.feature:22
Given <state> without a table # features/outline_sample.feature:6
Given <other_state> without a table # features/outline_sample.feature:7
Given passing without a table # features/search_sample.feature:4
Given passing without a table # features/search_sample.feature:7
Given <state> without a table # features/search_sample.feature:19
/^failing without a table$/ # features/step_definitions/sample_steps.rb:15
Given failing without a table # features/background/failing_background.feature:5
Given failing without a table # features/background/scenario_outline_failing_background.feature:4
Given failing without a table # features/search_sample.feature:10
Given <state> without a table # features/search_sample.feature:13
/^a step definition that calls an undefined step$/ # features/step_definitions/sample_steps.rb:19
Given a step definition that calls an undefined step # features/call_undefined_step_from_step_def.feature:4
/^call step "(.*)"$/ # features/step_definitions/sample_steps.rb:23
Expand Down
6 changes: 3 additions & 3 deletions lib/cucumber/ast/feature_element.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ def name_line_lengths
end
end

def matches_scenario_names?(scenario_names)
scenario_names.detect{|name| name == @name}
end
def matches_scenario_names?(scenario_name_regexps)
scenario_name_regexps.detect{|name| name =~ @name}
end

def backtrace_line(name = "#{@keyword} #{@name}", line = @line)
@feature.backtrace_line(name, line) if @feature
Expand Down
4 changes: 2 additions & 2 deletions lib/cucumber/ast/visitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ def initialize(step_mother)
end

def matches_scenario_names?(node)
scenario_names = options[:scenario_names] || []
scenario_names.empty? || node.matches_scenario_names?(scenario_names)
scenario_name_regexps = options[:name_regexps] || []
scenario_name_regexps.empty? || node.matches_scenario_names?(scenario_name_regexps)
end

def visit_features(features)
Expand Down
29 changes: 15 additions & 14 deletions lib/cucumber/cli/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,11 @@ def parse!(args)
"with or without the @ prefix.") do |v|
@options[:include_tags], @options[:exclude_tags] = *parse_tags(v)
end
opts.on("-s SCENARIO", "--scenario SCENARIO",
"Only execute the scenario with the given name. If this option",
"is given more than once, run all the specified scenarios.") do |v|
@options[:scenario_names] << v
opts.on("-n NAME", "--name NAME",
"Only execute the feature elements which match part of the given name.",
"If this option is given more than once, it will match against all the",
"given names.") do |v|
@options[:name_regexps] << /#{v}/
end
opts.on("-e", "--exclude PATTERN", "Don't run feature files matching PATTERN") do |v|
@options[:excludes] << v
Expand Down Expand Up @@ -334,16 +335,16 @@ def list_languages

def default_options
{
:strict => false,
:require => nil,
:lang => 'en',
:dry_run => false,
:formats => {},
:excludes => [],
:include_tags => [],
:exclude_tags => [],
:scenario_names => [],
:diff_enabled => true
:strict => false,
:require => nil,
:lang => 'en',
:dry_run => false,
:formats => {},
:excludes => [],
:include_tags => [],
:exclude_tags => [],
:name_regexps => [],
:diff_enabled => true
}
end

Expand Down
26 changes: 18 additions & 8 deletions lib/cucumber/parser/feature.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ def has_tags?(tag_names)
end

def build(filter)
if(filter.nil? || feature_elements.accept?(filter))
background = bg.respond_to?(:build) ? bg.build : nil
if(filter.nil? || feature_elements.accept?(filter) || (!bg.empty? && filter.accept?(bg)))
background = bg.respond_to?(:build) ? bg.build : nil
Ast::Feature.new(
background,
comment.build,
Expand Down Expand Up @@ -481,6 +481,16 @@ def steps
end

module Background1

def matches_name?(regexp_to_match)
name.build =~ regexp_to_match
end

def has_tags?(tag_names)
feature_tags = self.parent.tags
feature_tags.has_tags?(tag_names)
end

def build
Ast::Background.new(
comment.build,
Expand Down Expand Up @@ -678,8 +688,8 @@ def has_tags?(tag_names)
tags.has_tags?(tag_names) || feature_tags.has_tags?(tag_names)
end

def matches_name?(name_to_match)
name.build == name_to_match
def matches_name?(regexp_to_match)
name.build =~ regexp_to_match
end

def build(background, filter)
Expand Down Expand Up @@ -816,8 +826,8 @@ def has_tags?(tag_names)
tags.has_tags?(tag_names) || feature_tags.has_tags?(tag_names)
end

def matches_name?(name_to_match)
name.build == name_to_match
def matches_name?(regexp_to_match)
name.build =~ regexp_to_match
end

def build(background, filter)
Expand Down Expand Up @@ -1148,8 +1158,8 @@ def outline_at_line?(line)
true
end

def matches_name?(name_to_match)
name.build == name_to_match
def matches_name?(regexp_to_match)
name.build =~ regexp_to_match
end

def build(filter, scenario_outline)
Expand Down
26 changes: 18 additions & 8 deletions lib/cucumber/parser/feature.tt
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ module Cucumber
end

def build(filter)
if(filter.nil? || feature_elements.accept?(filter))
background = bg.respond_to?(:build) ? bg.build : nil
if(filter.nil? || feature_elements.accept?(filter) || (!bg.empty? && filter.accept?(bg)))
background = bg.respond_to?(:build) ? bg.build : nil
Ast::Feature.new(
background,
comment.build,
Expand Down Expand Up @@ -77,6 +77,16 @@ module Cucumber

rule background
comment white background_keyword space* name:lines_to_keyword? (eol+ / eof) steps {

def matches_name?(regexp_to_match)
name.build =~ regexp_to_match
end

def has_tags?(tag_names)
feature_tags = self.parent.tags
feature_tags.has_tags?(tag_names)
end

def build
Ast::Background.new(
comment.build,
Expand Down Expand Up @@ -118,8 +128,8 @@ module Cucumber
tags.has_tags?(tag_names) || feature_tags.has_tags?(tag_names)
end

def matches_name?(name_to_match)
name.build == name_to_match
def matches_name?(regexp_to_match)
name.build =~ regexp_to_match
end

def build(background, filter)
Expand Down Expand Up @@ -154,8 +164,8 @@ module Cucumber
tags.has_tags?(tag_names) || feature_tags.has_tags?(tag_names)
end

def matches_name?(name_to_match)
name.build == name_to_match
def matches_name?(regexp_to_match)
name.build =~ regexp_to_match
end

def build(background, filter)
Expand Down Expand Up @@ -233,8 +243,8 @@ module Cucumber
true
end

def matches_name?(name_to_match)
name.build == name_to_match
def matches_name?(regexp_to_match)
name.build =~ regexp_to_match
end

def build(filter, scenario_outline)
Expand Down
6 changes: 3 additions & 3 deletions lib/cucumber/parser/treetop_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def initialize(lines, options)
@lines = lines
@include_tags = options[:include_tags] || []
@exclude_tags = options[:exclude_tags] || []
@names = options[:scenario_names] || []
@name_regexps = options[:name_regexps] || []
end

def accept?(syntax_node)
Expand Down Expand Up @@ -48,7 +48,7 @@ def excluded_by_tags?(syntax_node)
end

def matches_names?(syntax_node)
@names.nil? || @names.empty? || @names.detect{|name| syntax_node.matches_name?(name)}
@name_regexps.nil? || @name_regexps.empty? || @name_regexps.detect{|name_regexp| syntax_node.matches_name?(name_regexp)}
end
end

Expand Down Expand Up @@ -111,4 +111,4 @@ class CompiledParser
include Cucumber::Parser::TreetopExt
end
end
end
end
5 changes: 5 additions & 0 deletions spec/cucumber/ast/feature_element_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ module Cucumber
text_length.should == 3
end
end

it "should support checking if its name matches a list of regexps" do
@name = 'test'
matches_scenario_names?([/es/]).should be_true
end

end
end
Expand Down
Loading

0 comments on commit 5eda40b

Please sign in to comment.