PageRenderTime 43ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/bundle/ruby/1.9.1/gems/webrat-0.7.3/spec/integration/rack/test/webrat_rack_test.rb

https://bitbucket.org/sqctest01/sample_app_3_1
Ruby | 74 lines | 59 code | 15 blank | 0 comment | 0 complexity | 9d84074a52b8f8347cb9d3e1943fc3f8 MD5 | raw file
Possible License(s): GPL-2.0
  1. require "rubygems"
  2. require File.dirname(__FILE__) + "/helper"
  3. class WebratRackTest < Test::Unit::TestCase
  4. include Rack::Test::Methods
  5. include Webrat::Methods
  6. include Webrat::Matchers
  7. include Webrat::HaveTagMatcher
  8. def build_rack_mock_session
  9. Rack::MockSession.new(app, "www.example.com")
  10. end
  11. def test_visits_pages
  12. visit "/"
  13. click_link "there"
  14. assert_have_tag("form[@method='post'][@action='/go']")
  15. end
  16. def test_submits_form
  17. visit "/go"
  18. fill_in "Name", :with => "World"
  19. fill_in "Email", :with => "world@example.org"
  20. click_button "Submit"
  21. assert_contain "Hello, World"
  22. assert_contain "Your email is: world@example.org"
  23. end
  24. def test_check_value_of_field
  25. visit "/"
  26. assert_equal field_labeled("Prefilled").value, "text"
  27. end
  28. def test_follows_internal_redirects
  29. visit "/internal_redirect"
  30. assert_contain "visit"
  31. end
  32. def test_does_not_follow_external_redirects
  33. visit "/external_redirect"
  34. assert last_response.redirect?
  35. end
  36. def test_absolute_url_redirect
  37. visit "/absolute_redirect"
  38. assert_contain "spam"
  39. end
  40. def test_upload_file
  41. visit "/upload"
  42. attach_file "File", __FILE__, "text/ruby"
  43. click_button "Upload"
  44. upload = Marshal.load(response_body)
  45. assert_equal "text/ruby", upload[:type]
  46. assert_equal "webrat_rack_test.rb", upload[:filename]
  47. assert_equal File.read(__FILE__), upload[:tempfile]
  48. end
  49. end
  50. class WebratRackSetupTest < Test::Unit::TestCase
  51. def test_usable_without_mixin
  52. rack_test_session = Rack::Test::Session.new(Rack::MockSession.new(app))
  53. adapter = Webrat::RackAdapter.new(rack_test_session)
  54. session = Webrat::Session.new(adapter)
  55. session.visit "/foo"
  56. assert_equal "spam", session.response_body
  57. assert_equal "spam", rack_test_session.last_response.body
  58. end
  59. end