Skip to content

Instantly share code, notes, and snippets.

@ssoroka
Created May 30, 2011 05:45

Revisions

  1. ssoroka created this gist May 30, 2011.
    22 changes: 22 additions & 0 deletions acceptance_helper.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    # Use feature, background, and scenario blocks to write acceptance tests in test/unit
    # which are really just integration tests. include capybara or webrat or something and voila.

    # test/acceptance_helper.rb
    require 'test_helper'

    module ActionDispatch
    class AcceptanceTest < ActionDispatch::IntegrationTest
    class << self
    alias :background :setup
    alias :scenario :test
    end
    end
    end

    class Object
    def feature(name, &block)
    klass = eval("class #{name.camelcase}AcceptanceTest < ActionDispatch::AcceptanceTest; self; end")
    klass.instance_eval(&block)
    end
    end

    17 changes: 17 additions & 0 deletions checkout_feature.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    # Now you can do something like this:

    require 'acceptance_helper'

    feature "Checkout" do
    background do
    create_user :name => "joe"
    login_as "joe"
    end

    scenario "should be able to complete a standard checkout" do
    visit "/checkout"
    click("checkout")
    # ...
    page.should have_css(".quote", :text => "Thank you")
    end
    end