emipair-webrat 0.0.1 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. data/.document +4 -0
  2. data/.gitignore +15 -0
  3. data/History.txt +34 -1
  4. data/Rakefile +45 -78
  5. data/VERSION +1 -0
  6. data/emipair-webrat.gemspec +354 -0
  7. data/lib/webrat.rb +3 -24
  8. data/lib/webrat/core/configuration.rb +5 -1
  9. data/lib/webrat/core/elements/field.rb +3 -3
  10. data/lib/webrat/core/logging.rb +3 -4
  11. data/lib/webrat/core/methods.rb +4 -4
  12. data/lib/webrat/core/mime.rb +11 -22
  13. data/lib/webrat/core/session.rb +27 -12
  14. data/lib/webrat/mechanize.rb +5 -1
  15. data/lib/webrat/{merb_session.rb → merb_adapter.rb} +4 -2
  16. data/lib/webrat/rack.rb +15 -14
  17. data/lib/webrat/rails.rb +7 -10
  18. data/lib/webrat/selenium.rb +0 -1
  19. data/lib/webrat/selenium/selenium_session.rb +8 -8
  20. data/lib/webrat/sinatra.rb +3 -36
  21. data/spec/fakes/{test_session.rb → test_adapter.rb} +6 -3
  22. data/spec/integration/mechanize/Rakefile +7 -0
  23. data/spec/integration/mechanize/config.ru +2 -0
  24. data/spec/integration/mechanize/sample_app.rb +20 -0
  25. data/spec/integration/mechanize/spec/mechanize_spec.rb +22 -0
  26. data/spec/integration/mechanize/spec/spec_helper.rb +27 -0
  27. data/spec/integration/merb/.gitignore +21 -0
  28. data/spec/integration/merb/Rakefile +35 -0
  29. data/spec/integration/merb/app/views/exceptions/not_acceptable.html.erb +63 -0
  30. data/spec/integration/merb/app/views/exceptions/not_found.html.erb +47 -0
  31. data/spec/integration/merb/app/views/layout/application.html.erb +12 -0
  32. data/spec/integration/merb/app/views/testing/show_form.html.erb +27 -0
  33. data/spec/integration/merb/app/views/testing/upload.html.erb +9 -0
  34. data/spec/integration/merb/spec/spec.opts +1 -0
  35. data/spec/integration/merb/spec/spec_helper.rb +2 -0
  36. data/spec/integration/merb/tasks/merb.thor/main.thor +150 -0
  37. data/spec/integration/rack/Rakefile +5 -0
  38. data/spec/integration/rack/app.rb +89 -0
  39. data/spec/integration/rack/test/helper.rb +21 -0
  40. data/spec/integration/rack/test/webrat_rack_test.rb +58 -52
  41. data/spec/integration/rails/.gitignore +3 -0
  42. data/spec/integration/rails/Rakefile +30 -0
  43. data/spec/integration/rails/app/views/buttons/show.html.erb +11 -0
  44. data/spec/integration/rails/app/views/fields/show.html.erb +9 -0
  45. data/spec/integration/rails/app/views/links/show.html.erb +5 -0
  46. data/spec/integration/rails/app/views/webrat/before_redirect_form.html.erb +4 -0
  47. data/spec/integration/rails/app/views/webrat/buttons.html.erb +11 -0
  48. data/spec/integration/rails/app/views/webrat/form.html.erb +28 -0
  49. data/spec/integration/rails/config/locales/en.yml +5 -0
  50. data/spec/integration/rails/public/404.html +30 -0
  51. data/spec/integration/rails/public/422.html +30 -0
  52. data/spec/integration/rails/public/500.html +33 -0
  53. data/spec/integration/rails/script/about +4 -0
  54. data/spec/integration/rails/script/console +3 -0
  55. data/spec/integration/rails/script/dbconsole +3 -0
  56. data/spec/integration/rails/script/destroy +3 -0
  57. data/spec/integration/rails/script/generate +3 -0
  58. data/spec/integration/rails/script/performance/benchmarker +3 -0
  59. data/spec/integration/rails/script/performance/profiler +3 -0
  60. data/spec/integration/rails/script/performance/request +3 -0
  61. data/spec/integration/rails/script/plugin +3 -0
  62. data/spec/integration/rails/script/process/inspector +3 -0
  63. data/spec/integration/rails/script/process/reaper +3 -0
  64. data/spec/integration/rails/script/process/spawner +3 -0
  65. data/spec/integration/rails/script/runner +3 -0
  66. data/spec/integration/rails/script/server +3 -0
  67. data/spec/integration/rails/test/test_helper.rb +2 -1
  68. data/spec/integration/sinatra/Rakefile +5 -0
  69. data/spec/integration/sinatra/test/test_helper.rb +2 -1
  70. data/spec/private/core/configuration_spec.rb +11 -2
  71. data/spec/private/core/field_spec.rb +1 -1
  72. data/spec/private/core/link_spec.rb +1 -1
  73. data/spec/private/core/session_spec.rb +5 -0
  74. data/spec/private/mechanize/{mechanize_session_spec.rb → mechanize_adapter_spec.rb} +4 -10
  75. data/spec/private/merb/{merb_session_spec.rb → merb_adapter_spec.rb} +5 -5
  76. data/spec/private/rails/{rails_session_spec.rb → rails_adapter_spec.rb} +17 -14
  77. data/spec/public/matchers/contain_spec.rb +4 -4
  78. data/spec/public/matchers/have_selector_spec.rb +2 -2
  79. data/spec/public/matchers/have_xpath_spec.rb +2 -2
  80. data/spec/rcov.opts +1 -0
  81. data/spec/spec.opts +2 -0
  82. data/spec/spec_helper.rb +3 -1
  83. metadata +172 -19
  84. data/lib/webrat/rack_test.rb +0 -32
  85. data/spec/integration/rack/rack_app.rb +0 -16
  86. data/spec/integration/rack/test/test_helper.rb +0 -20
  87. data/spec/private/core/logging_spec.rb +0 -10
@@ -0,0 +1,5 @@
1
+ require "rake/testtask"
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.test_files = FileList["test/*_test.rb"]
5
+ end
@@ -0,0 +1,89 @@
1
+ require "rubygems"
2
+ require "sinatra/base"
3
+
4
+ class RackApp < Sinatra::Base
5
+ use_in_file_templates!
6
+
7
+ get "/" do
8
+ erb :home
9
+ end
10
+
11
+ get "/go" do
12
+ erb :go
13
+ end
14
+
15
+ get "/internal_redirect" do
16
+ redirect "/"
17
+ end
18
+
19
+ get "/external_redirect" do
20
+ redirect "http://google.com"
21
+ end
22
+
23
+ get "/absolute_redirect" do
24
+ redirect URI.join(request.url, "foo").to_s
25
+ end
26
+
27
+ get "/foo" do
28
+ "spam"
29
+ end
30
+
31
+ post "/go" do
32
+ @user = params[:name]
33
+ @email = params[:email]
34
+ erb :hello
35
+ end
36
+
37
+ get "/upload" do
38
+ erb :uploader
39
+ end
40
+
41
+ post "/upload" do
42
+ params[:uploaded_file].to_yaml
43
+ end
44
+ end
45
+
46
+ __END__
47
+ @@ layout
48
+ <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
49
+ <html>
50
+ <title>sinatra testing with webrat</title>
51
+ <body>
52
+ <%= yield %>
53
+ </body>
54
+ </html>
55
+
56
+ @@ home
57
+ <p> visit <a href="/go">there</a></p>
58
+
59
+ <form>
60
+ <label>
61
+ Prefilled
62
+ <input type="text" name="prefilled" value="text" />
63
+ </label>
64
+ </form>
65
+
66
+ @@ go
67
+ <form method="post" action="/go">
68
+ <div>
69
+ <label for="name">Name</label>
70
+ <input type="text" name="name" id="name">
71
+ </div>
72
+ <div>
73
+ <label for="email">Email</label>
74
+ <input type="text" name="email" id="email">
75
+ </div>
76
+ <input type="submit" value="Submit" />
77
+ </form>
78
+
79
+ @@ hello
80
+ <p>Hello, <%= @user %></p>
81
+ <p>Your email is: <%= @email %></p>
82
+
83
+ @@ uploader
84
+ <form action="/upload" method="post">
85
+ <label>
86
+ File <input type="file" name="uploaded_file" />
87
+ </label>
88
+ <input type="submit" value="Upload">
89
+ </form>
@@ -0,0 +1,21 @@
1
+ require "rubygems"
2
+ require "test/unit"
3
+ require "rack/test"
4
+ # require "redgreen"
5
+
6
+ $LOAD_PATH.unshift File.dirname(__FILE__) + "/../../../../lib"
7
+ require "webrat"
8
+ require File.dirname(__FILE__) + "/../app"
9
+
10
+ Webrat.configure do |config|
11
+ config.mode = :rack
12
+ end
13
+
14
+ class Test::Unit::TestCase
15
+ def app
16
+ Rack::Builder.new {
17
+ use Rack::Lint
18
+ run RackApp.new
19
+ }
20
+ end
21
+ end
@@ -1,67 +1,73 @@
1
- require File.dirname(__FILE__) + "/test_helper"
2
- require File.dirname(__FILE__) + "/../rack_app"
1
+ require File.dirname(__FILE__) + "/helper"
3
2
 
4
3
  class WebratRackTest < Test::Unit::TestCase
5
- def test_visit_returns_response
6
- response = visit "/"
7
- assert response.ok?
4
+ include Rack::Test::Methods
5
+ include Webrat::Methods
6
+ include Webrat::Matchers
7
+ include Webrat::HaveTagMatcher
8
+
9
+ def build_rack_mock_session
10
+ Rack::MockSession.new(app, "www.example.com")
8
11
  end
9
12
 
10
- def test_last_response_is_available
11
- visit "/"
12
- assert last_response.ok?
13
+ def test_visits_pages
14
+ visit "/"
15
+ click_link "there"
16
+
17
+ assert_have_tag("form[@method='post'][@action='/go']")
18
+ end
19
+
20
+ def test_submits_form
21
+ visit "/go"
22
+ fill_in "Name", :with => "World"
23
+ fill_in "Email", :with => "world@example.org"
24
+ click_button "Submit"
25
+
26
+ assert_contain "Hello, World"
27
+ assert_contain "Your email is: world@example.org"
13
28
  end
14
29
 
15
- def test_last_request_is_available
30
+ def test_check_value_of_field
16
31
  visit "/"
17
- assert_equal "/", last_request.env["PATH_INFO"]
32
+ assert_equal field_labeled("Prefilled").value, "text"
18
33
  end
19
34
 
20
- # def test_redirects
21
- # visit "/redirect_absolute_url"
22
- # assert_equal "spam", response_body
23
- # end
35
+ def test_follows_internal_redirects
36
+ visit "/internal_redirect"
37
+ assert_contain "visit"
38
+ end
24
39
 
25
- def test_assertions_after_visit
26
- visit "/"
27
- assert_contain "Hello World"
40
+ def test_does_not_follow_external_redirects
41
+ visit "/external_redirect"
42
+ assert last_response.redirect?
28
43
  end
29
44
 
30
- def test_assertions_after_visit
31
- get "/"
32
- assert_contain "Hello World"
45
+ def test_absolute_url_redirect
46
+ visit "/absolute_redirect"
47
+ assert_contain "spam"
33
48
  end
34
49
 
35
- # def test_visits_pages
36
- # visit "/"
37
- # assert response_body.include?("visit")
38
- #
39
- # click_link "there"
40
- # assert response_body.include?('<form method="post" action="/go">')
41
- # end
42
- #
43
- # def test_submits_form
44
- # visit "/go"
45
- # fill_in "Name", :with => "World"
46
- # fill_in "Email", :with => "world@example.org"
47
- # click_button "Submit"
48
- #
49
- # assert response_body.include?("Hello, World")
50
- # assert response_body.include?("Your email is: world@example.org")
51
- # end
52
- #
53
- # def test_check_value_of_field
54
- # visit "/"
55
- # assert field_labeled("Prefilled").value, "text"
56
- # end
57
- #
58
- # def test_follows_internal_redirects
59
- # visit "/internal_redirect"
60
- # assert response_body.include?("visit")
61
- # end
62
- #
63
- # def test_does_not_follow_external_redirects
64
- # visit "/external_redirect"
65
- # assert response_code == 302
66
- # end
50
+ def test_upload_file
51
+ visit "/upload"
52
+ attach_file "File", __FILE__, "text/ruby"
53
+ click_button "Upload"
54
+
55
+ upload = YAML.load(response_body)
56
+ assert_equal "text/ruby", upload[:type]
57
+ assert_equal "webrat_rack_test.rb", upload[:filename]
58
+ assert upload[:tempfile].respond_to?(:read)
59
+ end
60
+ end
61
+
62
+ class WebratRackSetupTest < Test::Unit::TestCase
63
+ def test_usable_without_mixin
64
+ rack_test_session = Rack::Test::Session.new(Rack::MockSession.new(app))
65
+ adapter = Webrat::RackAdapter.new(rack_test_session)
66
+ session = Webrat::Session.new(adapter)
67
+
68
+ session.visit "/foo"
69
+
70
+ assert_equal "spam", session.response_body
71
+ assert_equal "spam", rack_test_session.last_response.body
72
+ end
67
73
  end
@@ -0,0 +1,3 @@
1
+ vendor/plugins/webrat
2
+ tmp/pids/*.pid
3
+ log/*.log
@@ -0,0 +1,30 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require(File.join(File.dirname(__FILE__), 'config', 'boot'))
5
+
6
+ require 'rake'
7
+ require 'rake/testtask'
8
+ require 'rake/rdoctask'
9
+
10
+ require 'tasks/rails'
11
+
12
+
13
+
14
+
15
+ namespace :test_unit do
16
+ desc "runs the test::unit based tests in webrat mode"
17
+ task :rails do
18
+ ENV['WEBRAT_INTEGRATION_MODE'] = 'rails'
19
+ Rake::Task['test:integration'].execute
20
+ end
21
+
22
+ desc "runs the test::unit based tests in selenium mode"
23
+ task :selenium do
24
+ ENV['WEBRAT_INTEGRATION_MODE'] = 'selenium'
25
+ Rake::Task['test:integration'].execute
26
+ end
27
+
28
+ desc "run both selenium and rails mode Test::Unit suites"
29
+ task :all => [:rails, :selenium]
30
+ end
@@ -0,0 +1,11 @@
1
+ <h1 id='form_title' class='form title'>Webrat Buttons Form</h1>
2
+
3
+ <% form_tag "/buttons" do %>
4
+ <input type="button" id="input_button_id" value="input_button_value" />
5
+ <input type="submit" id="input_submit_id" value="input_submit_value" />
6
+ <input type="image" id="input_image_id" value="input_image_value" alt="input_image_alt" src="" />
7
+
8
+ <button type="button" id="button_button_id" value="button_button_value">button_button_text</button>
9
+ <button type="submit" id="button_submit_id" value="button_submit_value">button_submit_text</button>
10
+ <button type="image" id="button_image_id" value="button_image_value">button_image_text</button>
11
+ <% end %>
@@ -0,0 +1,9 @@
1
+ <h1>Webrat Fields Page</h1>
2
+ <h2>Filling In</h2>
3
+ <ul>
4
+ <li><input type="text" name="field_by_name" value="" /></li>
5
+ <li><input type="text" name="rails[naming]" value="" /></li>
6
+ <li><input type="text" id="field_by_id" value="" /></li>
7
+ <li><label for="field_by_label_id">FieldByLabelId</label><input type="text" id="field_by_label_id" /></li>
8
+ <li><label for="field_by_label_with_special_characters">[Field]:</label><input type="text" id="field_by_label_with_special_characters" /></li>
9
+ </ul>
@@ -0,0 +1,5 @@
1
+ <h1>Webrat Links Page</h1>
2
+ <a href="/links?value=LinkByText">LinkByText</a><br />
3
+ <a href="/links?value=link_by_id" id="link_by_id">id</a><br />
4
+ <a href="/links?value=LinkByTitle" title="LinkByTitle">title</a><br />
5
+ <a href="/links?value=link_with_parens">Link With (parens)</a><br />
@@ -0,0 +1,4 @@
1
+ <% form_tag redirect_to_show_params_path do %>
2
+ <%= label_tag 'text_field', 'Text Field' %><%= text_field_tag "text_field" %>
3
+ <%= submit_tag "Test" %>
4
+ <% end %>
@@ -0,0 +1,11 @@
1
+ <h1 id='form_title' class='form title'>Webrat Buttons Form</h1>
2
+
3
+ <% form_tag submit_path do %>
4
+ <input type="button" id="input_button_id" value="input_button_value">
5
+ <input type="submit" id="input_submit_id" value="input_submit_value">
6
+ <input type="image" id="input_image_id" value="input_image_value" alt="input_image_alt" src="">
7
+
8
+ <button type="button" id="button_button_id" value="button_button_value">button_button_text</button>
9
+ <button type="submit" id="button_submit_id" value="button_submit_value">button_submit_text</button>
10
+ <button type="image" id="button_image_id" value="button_image_value">button_image_text</button>
11
+ <% end %>
@@ -0,0 +1,28 @@
1
+ <h1 id='form_title' class='form title'>Webrat Form</h1>
2
+
3
+ <% form_tag submit_path do %>
4
+ <label>
5
+ Text field <%= text_field_tag "text_field" %>
6
+ </label>
7
+
8
+ <label>
9
+ TOS <%= check_box_tag "tos" %>
10
+ </label>
11
+
12
+ <label>
13
+ Prefilled
14
+ <input type="text" name="prefilled" value="text" />
15
+ </label>
16
+
17
+ <label>
18
+ <%= select_tag "month", "<option></option><option>January</option>" %>
19
+ </label>
20
+
21
+ <% div_for FakeModel.new do %>
22
+ <label>
23
+ Object field <%= text_field_tag "object_field" %>
24
+ </label>
25
+ <% end %>
26
+
27
+ <%= submit_tag "Test" %>
28
+ <% end %>
@@ -0,0 +1,5 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
5
+ hello: "Hello world"
@@ -0,0 +1,30 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+
6
+ <head>
7
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
8
+ <title>The page you were looking for doesn't exist (404)</title>
9
+ <style type="text/css">
10
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
11
+ div.dialog {
12
+ width: 25em;
13
+ padding: 0 4em;
14
+ margin: 4em auto 0 auto;
15
+ border: 1px solid #ccc;
16
+ border-right-color: #999;
17
+ border-bottom-color: #999;
18
+ }
19
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
20
+ </style>
21
+ </head>
22
+
23
+ <body>
24
+ <!-- This file lives in public/404.html -->
25
+ <div class="dialog">
26
+ <h1>The page you were looking for doesn't exist.</h1>
27
+ <p>You may have mistyped the address or the page may have moved.</p>
28
+ </div>
29
+ </body>
30
+ </html>
@@ -0,0 +1,30 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+
6
+ <head>
7
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
8
+ <title>The change you wanted was rejected (422)</title>
9
+ <style type="text/css">
10
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
11
+ div.dialog {
12
+ width: 25em;
13
+ padding: 0 4em;
14
+ margin: 4em auto 0 auto;
15
+ border: 1px solid #ccc;
16
+ border-right-color: #999;
17
+ border-bottom-color: #999;
18
+ }
19
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
20
+ </style>
21
+ </head>
22
+
23
+ <body>
24
+ <!-- This file lives in public/422.html -->
25
+ <div class="dialog">
26
+ <h1>The change you wanted was rejected.</h1>
27
+ <p>Maybe you tried to change something you didn't have access to.</p>
28
+ </div>
29
+ </body>
30
+ </html>
@@ -0,0 +1,33 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+
4
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5
+
6
+ <head>
7
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
8
+ <title>We're sorry, but something went wrong (500)</title>
9
+ <style type="text/css">
10
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
11
+ div.dialog {
12
+ width: 25em;
13
+ padding: 0 4em;
14
+ margin: 4em auto 0 auto;
15
+ border: 1px solid #ccc;
16
+ border-right-color: #999;
17
+ border-bottom-color: #999;
18
+ }
19
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
20
+ </style>
21
+ </head>
22
+
23
+ <body>
24
+ <!-- This file lives in public/500.html -->
25
+ <div class="dialog">
26
+ <h1>We're sorry, but something went wrong.</h1>
27
+ <p>We've been notified about this issue and we'll take a look at it shortly.</p>
28
+ <p><small>(If you're the administrator of this website, then please read
29
+ the log file "<%=h RAILS_ENV %>.log"
30
+ to find out what went wrong.)</small></p>
31
+ </div>
32
+ </body>
33
+ </html>