Created — forked from ssoroka/acceptance_helper.rb

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Use feature, background, and scenario blocks to write acceptance tests in test/unit

View acceptance_helper.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
# 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)
Kernel.
const_get(name.classify+"AcceptanceTest").
instance_eval(&block)
end
end
 
View acceptance_helper.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.