Skip to content

Commit

Permalink
can use commas and 'but's instead of just 'and' to join sentences
Browse files Browse the repository at this point in the history
  • Loading branch information
triskweline committed Sep 4, 2010
1 parent 1ca901a commit c650472
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
6 changes: 5 additions & 1 deletion README.rdoc
Expand Up @@ -24,7 +24,11 @@ You can also refer to the last created object of a kind by saying "above":
Boolean attributes can be set by appending "which", "that" or "who" at the end:
Given there is a movie which is awesome
And there is a movie with the name "Sunshine" that is not a comedy
And there is a director who is popular
And there is a director who is popular

Instead of "and" you can also use "but" and commas to join sentences:
Given there is a movie which is awesome, popular and successful but not science fiction
And there is a director with the income "500000" but with the account balance "-30000"

== Factory support

Expand Down
4 changes: 2 additions & 2 deletions lib/cucumber/factory.rb
Expand Up @@ -34,15 +34,15 @@ def parse_creation(world, raw_model, raw_variant, raw_attributes, raw_boolean_at
model_class = model_class_from_prose(raw_model)
attributes = {}
if raw_attributes.try(:strip).present?
raw_attributes.scan(/(?:the|and|with| )+(.*?) ("([^\"]*)"|above)/).each do |fragment|
raw_attributes.scan(/(?:the|and|with|but|,| )+(.*?) ("([^\"]*)"|above)/).each do |fragment|
attribute = attribute_name_from_prose(fragment[0])
value_type = fragment[1] # 'above' or a quoted string
value = fragment[2] # the value string without quotes
attributes[attribute] = attribute_value(world, model_class, attribute, value_type, value)
end
end
if raw_boolean_attributes.try(:strip).present?
raw_boolean_attributes.scan(/(?:which|who|that|is| )*(not )?(.+?)(?: and |$)/).each do |fragment|
raw_boolean_attributes.scan(/(?:which|who|that|is| )*(not )?(.+?)(?: and | but |,|$)+/).each do |fragment|
flag = !fragment[0] # if not ain't there, this is true
attribute = attribute_name_from_prose(fragment[1])
attributes[attribute] = flag
Expand Down
16 changes: 16 additions & 0 deletions spec/steps_spec.rb
Expand Up @@ -71,6 +71,13 @@ def self.factories
@step_mother.invoke('there is a movie with the title "Sunshine" and the year "2007"')
end

it "should allow to join attribute lists with 'and's, commas and 'but's" do
movie = Movie.new
Movie.stub(:new => movie)
movie.should_receive(:"attributes=").with({ :title => "Sunshine", :year => "2007", :box_office_result => "32000000" }, false)
@step_mother.invoke('there is a movie with the title "Sunshine", the year "2007" but with the box office result "32000000"')
end

it "should apply Cucumber transforms to attribute values" do
movie = Movie.new
Movie.stub(:new => movie)
Expand Down Expand Up @@ -160,4 +167,13 @@ def self.factories
jane.deleted.should equal(true)
end

it "should allow to join boolean attribute lists with 'and's, commas and 'but's" do
@step_mother.invoke('there is a user who is locked, scared, but scared by spiders and deleted')
jane = User.find(:last, :order => 'id')
jane.locked.should equal(true)
jane.scared.should equal(true)
jane.scared_by_spiders.should equal(true)
jane.deleted.should equal(true)
end

end

0 comments on commit c650472

Please sign in to comment.