StepSpecr provides a ‘testing’ framework for speccing Given/When/Then steps within Rspec examples.
This lets you implement GWT-steps the BDD way.
StepSpecr is a Rails plugin, so…
$ rails greatapp
$ cd greatappIt’s necessary to have edge rails in order to use the plugin script with github (where stepspecr is hosted).
$ rake rails:freeze:edgeStepSpecr depends on rspec:
$ script/plugin install git://github.com/dchelimsky/rspec.git
$ script/plugin install git://github.com/dchelimsky/rspec-rails.git
$ script/generate rspecInstall StepSpecr:
$ script/plugin install git://github.com/mhennemeyer/stepspecr.git
$ script/generate stepspecr

By bootstraping the project (script/generate stepspecr) a example_step_spec.rb was generated. Run it now to see if everything works.
$ script/spec—format -c specdoc spec/steps/example_step_spec.rb
( I'll work on performance :) )
Create a new spec file:
$ mate greatapp/spec/steps/great_step_spec.rbThe spec needs to require its helper file:
require File.expand_path(File.dirname(FILE) + ”/stepspecr_helper.rb”)(You can copy it from the example_step_spec.)
Given a great_model
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
require File.expand_path(File.dirname(__FILE__) + "/stepspecr_helper.rb") describe "Given a great_model" do it "should create a great_model" do StepSpecr.spec "Given a great_model" do step_group :great_models before do class GreatModel end GreatModel.should_receive(:create) end end end end |
$ script/spec—format -c specdoc spec/steps/great_steps_spec.rb
Create the step file:
$ mate greatapp/stories/steps/great_steps.rbThe failure message was: ‘Didn’t find step’. Let’s write the step without implementation to get a more meaningful directive:
1 2 3 4 5 6 |
steps_for :great_models do Given "a great_model" do end end |
$ script/spec—format specdoc spec/steps/great_step_spec.rb
Now the system tells us what to do: ‘Mock expected :create … ‘
1 2 3 4 5 6 7 |
steps_for :great_models do Given "a great_model" do GreatModel.create end end |
$ script/spec—format specdoc spec/steps/great_step_spec.rb
Crafting Rspec Steps with step_eval and DRYing them with a Helper
Part 2
Part 3
Sorry, comments are closed for this article.
Yeah, that looks interesting. One quick question: Why is the first failing example red and the second some kind of purple?
April 22nd, 2008 at 02:40 PM