Created
May 30, 2011 05:45
-
-
Save ssoroka/998500 to your computer and use it in GitHub Desktop.
Use feature, background, and scenario blocks to write acceptance tests in test/unit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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