I committed a first cut at blockless Givens/Whens/Thens to RSpec’s
trunk:
cd /path/to/rspec/project
svn up
cd rspec
bin/spec examples/story/calculator.rb
Take a look at examples/story/calculator.rb to see what’s going on.
Needs docs!!!
Thoughts welcome.
I’ve also got a cut at the plain text parser checked in, but it’s not
hooked up to anything yet. However, now that we can do blockless GWT,
hooking the parser up to the rest is just a matter of a simple adapter
and logistics. Look for it in the next few days.
How about something like match_given, match_when, match_then?
I see what you’re saying. However I think it’s helpful to put the
g/w/t right at the beginning of the method name, it’s easier to
distinguish between them. You can look at the first character and
know what’s going on. With step_matcher(:given…) you have to skip
the first 12 characters. That feels noisy and dirty to me, and I
think the readability overcomes the verb phrase problem.
Though I agree with you and I’m not in love with given_matcher. hrm,
needs more thought.
Could this:
step_matcher(:then, “the sum should be $sum”) do |sum|
when_matcher(“they are added”) do
they sound like verb phrases - “given matcher”, “when matcher”, "then
Though I agree with you and I’m not in love with given_matcher. hrm,
needs more thought.
What if it were wrapped in something like this:
step_matchers do
given_matcher(“an addend of $addend”) do |addend| @adder ||= Adder.new @adder << addend.to_i
end
when_matcher(“they are added”) do @sum = @adder.sum
end
then_matcher(“the sum should be $sum”) do |sum| @sum.should == sum.to_i
end
end
step_matchers provides context for the [given|when|then]_matcher
methods. WDYT?
I like the idea of mapping a story to a vocabulary. I just don’t like
doing it in the story text itself - seems more dev-facing than
customer-facing. But perhaps the notion of vocabulary is a good thing
to have front and center to help the customer understand the
constraints of what can be written. Need to think about that some
more.
Easier to type, sure. I’m not in love w/ the names yet though because
think the readability overcomes the verb phrase problem.
end
step_matchers provides context for the [given|when|then]_matcher methods. WDYT?
I like that more. It also provides a natural insertion point for
naming libraries.
step_matchers(“arithmetic”) do
given_matcher(“an addend of $addend”) do |addend| @adder ||= Adder.new @adder << addend.to_i
end
when_matcher(“they are added”) do @sum = @adder.sum
end
then_matcher(“the sum should be $sum”) do |sum| @sum.should == sum.to_i
end
end
I like the idea of mapping a story to a vocabulary. I just don’t like
doing it in the story text itself - seems more dev-facing than
customer-facing. But perhaps the notion of vocabulary is a good thing
to have front and center to help the customer understand the
constraints of what can be written. Need to think about that some
more.
I know what you mean. It comes across too much as “import some_lib”
to me. Not quite sure what to do about that.
One other idea I had was sticking similar stories in subdirs, each of
which has a helper.rb file. That helper file would load up whatever
step libraries you would want to apply to each story in that dir.