Bei schrieb: > Hi > > I'm using story runner of RSpec now. What I'm trying to do is > initializing the @selenium before any steps of one story is executing, > and stop @selenium after any story is finished. just as @BeforeClass > and @AfterClass in jUnit > Any suggestions on this? > > Thanks!!! >
Hi, my helpers/selenium_helper.rb file look like that: # Alias some more ruby-like methods on SeleniumDriver, to make it play # better with rspec matchers. module Selenium class SeleniumDriver alias_method :original_method_missing, :method_missing def method_missing method_name, *args if method_name.to_s =~ /^has_.*\?$/ real_method = method_name.to_s.sub /has_(.*)\?$/, 'is_\1' if respond_to? real_method return send(real_method, args) end elsif respond_to?(real_method = "get_" + method_name.to_s) return send(real_method) end return original_method_missing(method_name, args) end end end $selenium_driver = nil unless $selenium_driver $selenium_listener_added = false unless $selenium_listener_added module StoryHelper def selenium $selenium_driver end Spec::Story::World.send :include, self end class SeleniumListener include Singleton def scenario_started(*args) $selenium_driver = Selenium::SeleniumDriver.new('localhost', 4444, '*firefox', 'http://localhost:3000/', 15000) $selenium_driver.start end def scenario_succeeded(*args) $selenium_driver.stop $selenium_driver = nil end alias :scenario_pending :scenario_succeeded alias :scenario_failed :scenario_succeeded end unless $selenium_listener_added Spec::Story::Runner.scenario_runner.add_listener(SeleniumListener.instance) $selenium_listener_added = true end Best wishes, Thomas _______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users