Skip to content

Commit

Permalink
Update specs for custom placeholder without specific regexp
Browse files Browse the repository at this point in the history
  • Loading branch information
hanachin committed Feb 3, 2016
1 parent 9d382d0 commit 11258ce
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
14 changes: 10 additions & 4 deletions examples/steps/steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@
end

step "there are the following monsters:" do |table|
@monsters = {}
$monsters = {}
table.hashes.each do |hash|
@monsters[hash['Name']] = hash['Hitpoints'].to_i
$monsters[hash['Name']] = hash['Hitpoints'].to_i
end
end

step ":name should have :count hitpoints" do |name, count|
@monsters[name].should eq(count.to_i)
step ":monster should have :count hitpoints" do |monster, count|
monster.should eq(count.to_i)
end

step "the monster sings the following song" do |song|
Expand Down Expand Up @@ -118,3 +118,9 @@
color.to_sym
end
end

placeholder :monster do
match do |name|
$monsters[name]
end
end
5 changes: 4 additions & 1 deletion spec/placeholder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,13 @@
placeholder = described_class.new(:test) do
match(/foo/) { :foo_bar }
match(/\d/) { |num| num.to_i }
match { |value| value.gsub(' ', '').to_sym }
end

expect(placeholder.apply('foo')).to eq :foo_bar
expect(placeholder.apply('bar')).to eq 'bar'
expect(placeholder.apply('bar')).to eq :bar
expect(placeholder.apply('"fizz buzz"')).to eq :fizzbuzz
expect(placeholder.apply("'fizz buzz'")).to eq :fizzbuzz
expect(placeholder.apply('5')).to eq 5
end

Expand Down

0 comments on commit 11258ce

Please sign in to comment.