3. A Simple Spec describe ProjectsController do context "logged in user" do before(:each) do @user = User.make ApplicationController.stub(:current_user).and_return(@user) End it "should do something" do @user.should_receive(:do_stuff).and_return(true) post :do_stuff end end end
9. Rspec.configure Rspec.configure do |c| c.filter = { :important => true } c.exclusion_filter = { :slow => true } End #Runs this block describe “tests”, :important => true do it “does something” do end #excludes this test it “does something slow”, :slow => true do end End #You can put lambdas in there too.
10. Custom Matchers RSpec::Matchers.define :be_in_zone do |zone| match do |player| player.in_zone?(zone) end failure_message_for_should do |player| # generate and return the appropriate string. end failure_message_for_should_not do |player| # generate and return the appropriate string. end description do # generate and return the appropriate string. end end
12. Create a new ControllerMacros module with methods that construct appropriate it() statements. And add something like: def get(action) define_method :do_request do get action end yield end
13. Capybara within("li#employee") do fill_in 'Name', :with => 'Jimmy' End save_and_open_page #opens a snapshot of page Capybara.default_wait_time #lets you set how long to wait between actions for ajax when you're checking content.
14. Capybara + WebDriver $ sudo gem install cucumber cucumber-rails $ ./script/generate cucumber --capybara --rspec $ RAILS_ENV=cucumber rake gems:install Capybara.default_driver = :selenium Or use tags(@javascript etc) and only use selenium for relevant tests: Capybara.javascript_driver = :selenium