aslak hellesoy wrote:
Of how you would use it. Assume that you have something like this for scenario-level before/after: class MySteps < Cucumber::Steps # Same as Story runnner steps_for(:my) Before do # This block will run before all scenarios that use steps from MySteps # Any scenarios not using any of these will not have this block run end Given /bla bla/ do end end Aslak
Ok here is an example from one of my current stories.... Modified to be Cucumber-like, although I see you put the Before and after in the steps, I'd p[refer them to be global, but could live with them in the steps class. Of course where would you put the scenarios before and after? They probably need to be global?
(Note I am not using Rails,this is an integration test against a Web Application testing the full stack using net/http and some helpers to wrap that. It can test remote servers, It also uses Sequel to test that the database gets setup properly, again a bunch of helpers lets me inject data directly into the database and test afterwards).
# setup several users each with their own web context # setup global database accessor BeforeFeature do # actual user names to login as user_names= %w(user50 user51 user52) $umap= {} $wr= {} user_names.each_with_index do |e, i| n= "user#{i+1}" $umap[n]= e $wr[n]= WebRequest.new end $users= {} $loggedin= {} $db= MyDBHelper.new('local', false) end # logout the users AfterFeature do $wr.each_value { |w| w.logout } end # called before each scenario # to clean up any state conatianing globals used to communicate between steps # and log out any user that was logged in during the previous Scenario BeforeScenario do $wr.each_key do |u| $wr[u].logout if $loggedin[u] end $last_error= nil $roomid= nil $roomobjectid= nil $last_doc= nil $bagid= nil end -- Jim Morris, http://blog.wolfman.com _______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users