Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added multiline string

  • Loading branch information...
commit 14f147bbbbff9d5eb5f4cd8ec18d07e79d02f05d 1 parent e7c630b
@jnicklas authored
View
8 examples/multiline_string.feature
@@ -0,0 +1,8 @@
+Feature: A feature with multiline strings
+ Scenario: This is a feature with multiline strings
+ When the monster sings the following song
+ """
+ Oh here be monsters
+ This is cool
+ """
+ Then the song should have 2 lines
View
11 examples/steps.rb
@@ -56,6 +56,17 @@
@monster.should <= 0
end
+step "there are the following monsters:" do |table|
+end
+
+step "the monster sings the following song" do |song|
+ @song = song
+end
+
+step "the song should have :count lines" do |count|
+ @song.to_s.split("\n").length.should eq(count)
+end
+
placeholder :count do
match /\d+/ do |count|
count.to_i
View
8 lib/turnip/builder.rb
@@ -74,13 +74,17 @@ def to_scenarios(examples)
rows.map do |row|
Scenario.new(@raw).tap do |scenario|
scenario.steps = steps.map do |step|
- step.gsub(/<([^>]*)>/) { |_| Hash[headers.zip(row)][$1] }
+ new_description = step.description.gsub(/<([^>]*)>/) { |_| Hash[headers.zip(row)][$1] }
+ Step.new(new_description, step.extra_arg)
end
end
end
end
end
+ class Step < Struct.new(:description, :extra_arg)
+ end
+
attr_reader :features
class << self
@@ -121,7 +125,7 @@ def examples(examples)
end
def step(step)
- @current_step_context.steps << step.name
+ @current_step_context.steps << Step.new(step.name, step.doc_string && step.doc_string.value)
end
def eof
View
10 lib/turnip/step_definition.rb
@@ -12,11 +12,13 @@ class Ambiguous < StandardError; end
attr_reader :expression, :block
class << self
- def execute(context, description)
- match = find(description)
- context.instance_exec(*match.params, &match.block)
+ def execute(context, step)
+ match = find(step.description)
+ params = match.params
+ params << step.extra_arg if step.extra_arg
+ context.instance_exec(*params, &match.block)
rescue Pending
- context.pending "the step '#{description}' is not implemented"
+ context.pending "the step '#{step.description}' is not implemented"
end
def add(expression, &block)
View
4 spec/builder_spec.rb
@@ -15,12 +15,12 @@
end
it "replaces placeholders in steps" do
- feature.scenarios[0].steps.should eq([
+ feature.scenarios[0].steps.map(&:description).should eq([
"there is a monster with 10 hitpoints",
"I attack the monster and do 13 points damage",
"the monster should be dead"
])
- feature.scenarios[1].steps.should eq([
+ feature.scenarios[1].steps.map(&:description).should eq([
"there is a monster with 8 hitpoints",
"I attack the monster and do 5 points damage",
"the monster should be alive"
View
2  spec/integration_spec.rb
@@ -11,6 +11,6 @@
end
it "prints out failures and successes" do
- @result.should include('12 examples, 1 failure, 1 pending')
+ @result.should include('13 examples, 1 failure, 1 pending')
end
end
View
18 spec/step_definition_spec.rb
@@ -31,14 +31,28 @@
it "executes a step in the given context" do
context = stub
Turnip::StepDefinition.add("there are :count monsters") { @testing = 123 }
- Turnip::StepDefinition.execute(context, "there are 23 monsters")
+ Turnip::StepDefinition.execute(context, stub(:description => "there are 23 monsters", :extra_arg => nil))
context.instance_variable_get(:@testing).should == 123
end
it "tells the context that the step is pending" do
context = stub
context.should_receive(:pending).with("the step 'there are 23 monsters' is not implemented")
- Turnip::StepDefinition.execute(context, "there are 23 monsters")
+ Turnip::StepDefinition.execute(context, stub(:description => "there are 23 monsters", :extra_arg => nil))
+ end
+
+ it "sends along arguments" do
+ context = stub
+ Turnip::StepDefinition.add("there are :count monsters") { |count| @testing = count.to_i }
+ Turnip::StepDefinition.execute(context, stub(:description => "there are 23 monsters", :extra_arg => nil))
+ context.instance_variable_get(:@testing).should == 23
+ end
+
+ it "sends along extra arguments" do
+ context = stub
+ Turnip::StepDefinition.add("there are :count monsters") { |count, extra| @testing = extra }
+ Turnip::StepDefinition.execute(context, stub(:description => "there are 23 monsters", :extra_arg => 'foo'))
+ context.instance_variable_get(:@testing).should == 'foo'
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.