Created
January 10, 2009 05:26
-
-
Save fairchild/45395 to your computer and use it in GitHub Desktop.
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
| require File.join(File.dirname(__FILE__), '..', 'test_helper') | |
| require "webrat" | |
| Webrat.configure do |config| | |
| config.mode = :rails | |
| config.open_error_files = false | |
| end | |
| module MyTestingDSL | |
| def logs_in(login, password) | |
| visit '/' ########### This method is undefined when called from line 47 | |
| fill_in "login", :with => login | |
| fill_in "password", :with => password | |
| click_button | |
| User.authenticate(login, password) | |
| end | |
| def visit_company_page(company) | |
| visit '/companies' | |
| .... | |
| end | |
| def post_an_ask(order_data) | |
| ..... | |
| end | |
| def accept_ask(order_data) | |
| visit_company_page(order_data[:company]) | |
| click_link "Accept #{order_data[:company]}" | |
| end | |
| end # of module | |
| class TradTest < ActionController::IntegrationTest | |
| include MyTestingDSL | |
| def test_user_flow_thru_first_trade | |
| @company = DataFactory.create_company({:name=>'facebook'}) | |
| @bob = create_a_valid_user('bob', 'bobs_secret') | |
| @sally = create_a_valid_user('sally', 'sallys_secret') | |
| logs_in('sally', 'sallys_secret') | |
| visit_company_page(@company) | |
| post_an_ask({:user => @sally, :company => @company, :shares => 10, :price => 12}) | |
| new_session do |bob| | |
| bob.logs_in('bob', 'bobs_secret') #### the webrat method defined in logs_in are not defined | |
| visit_company_page(@company) | |
| accept_ask | |
| end | |
| visit "/users/#{@sally.id}" | |
| assert_select "a", /Ask was accepted/ | |
| end | |
| def new_session | |
| open_session do |sess| | |
| puts self # test_user_flow_thru_first_trade(TradTest) | |
| puts sess.class # ActionController::Integration::Session | |
| sess.extend(MyTestingDSL) | |
| sess.extend(Webrat) | |
| yield sess if block_given? | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment