diff --git a/lib/webrat/core/field.rb b/lib/webrat/core/field.rb index 8a580a6..8145aaf 100644 --- a/lib/webrat/core/field.rb +++ b/lib/webrat/core/field.rb @@ -258,8 +258,17 @@ module Webrat if @value.nil? super else - file = content_type ? ActionController::TestUploadedFile.new(@value, content_type) : ActionController::TestUploadedFile.new(@value) - replace_param_value(super, @value, file) + replace_param_value(super, @value, test_uploaded_file) + end + end + + protected + + def test_uploaded_file + if content_type + ActionController::TestUploadedFile.new(@value, content_type) + else + ActionController::TestUploadedFile.new(@value) end end diff --git a/spec/api/attaches_file_spec.rb b/spec/api/attaches_file_spec.rb index a6792c3..edf0e74 100644 --- a/spec/api/attaches_file_spec.rb +++ b/spec/api/attaches_file_spec.rb @@ -5,8 +5,8 @@ describe "attaches_file" do @session = Webrat::TestSession.new @filename = __FILE__ - @uploaded_file = mock - ActionController::TestUploadedFile.stubs(:new).returns(@uploaded_file) + @uploaded_file = mock("uploaded file") + ActionController::TestUploadedFile.stub!(:new).and_return(@uploaded_file) end it "should fail if no file field found" do @@ -24,7 +24,7 @@ describe "attaches_file" do EOS - @session.expects(:post).with("/widgets", { "widget" => { "file" => "" } }) + @session.should_receive(:post).with("/widgets", { "widget" => { "file" => "" } }) @session.clicks_button end @@ -36,7 +36,7 @@ describe "attaches_file" do EOS - @session.expects(:post).with("/widgets", { "widget" => { "file" => @uploaded_file } }) + @session.should_receive(:post).with("/widgets", { "widget" => { "file" => @uploaded_file } }) @session.attaches_file "Document", @filename @session.clicks_button end @@ -51,7 +51,7 @@ describe "attaches_file" do EOS - @session.expects(:post).with("/widgets", { "widget" => { "files" => [@uploaded_file, @uploaded_file] } }) + @session.should_receive(:post).with("/widgets", { "widget" => { "files" => [@uploaded_file, @uploaded_file] } }) @session.attaches_file "Document", @filename @session.attaches_file "Spreadsheet", @filename @session.clicks_button @@ -65,7 +65,7 @@ describe "attaches_file" do EOS - ActionController::TestUploadedFile.expects(:new).with(@filename, "image/png").returns(@uploaded_file) + ActionController::TestUploadedFile.should_receive(:new).with(@filename, "image/png").any_number_of_times @session.attaches_file "Picture", @filename, "image/png" @session.clicks_button end diff --git a/spec/api/checks_spec.rb b/spec/api/checks_spec.rb index bc9da62..2599b4f 100644 --- a/spec/api/checks_spec.rb +++ b/spec/api/checks_spec.rb @@ -33,7 +33,7 @@ describe "checks" do EOS - @session.expects(:get).with("/login", "user" => {"tos" => "1"}) + @session.should_receive(:get).with("/login", "user" => {"tos" => "1"}) @session.checks "TOS" @session.clicks_button end @@ -45,7 +45,7 @@ describe "checks" do EOS - @session.expects(:post).with("/login", "remember_me" => "on") + @session.should_receive(:post).with("/login", "remember_me" => "on") @session.checks "remember_me" @session.clicks_button end @@ -57,7 +57,7 @@ describe "checks" do EOS - @session.expects(:post).with("/login", "remember_me" => "yes") + @session.should_receive(:post).with("/login", "remember_me" => "yes") @session.checks "remember_me" @session.clicks_button end @@ -96,7 +96,7 @@ describe "unchecks" do EOS - @session.expects(:get).with("/login", "user" => {"tos" => "0"}) + @session.should_receive(:get).with("/login", "user" => {"tos" => "0"}) @session.checks "TOS" @session.unchecks "TOS" @session.clicks_button @@ -109,7 +109,7 @@ describe "unchecks" do EOS - @session.expects(:post).with("/login", {}) + @session.should_receive(:post).with("/login", {}) @session.unchecks "remember_me" @session.clicks_button end diff --git a/spec/api/chooses_spec.rb b/spec/api/chooses_spec.rb index 1d38d51..3c8ed5f 100644 --- a/spec/api/chooses_spec.rb +++ b/spec/api/chooses_spec.rb @@ -34,24 +34,7 @@ describe "chooses" do EOS - @session.expects(:get).with("/login", "user" => {"gender" => "M"}) - @session.chooses "Male" - @session.clicks_button - end - - it "should use any of the button's labels" do - @session.response_body = <<-EOS -
- EOS - @session.expects(:get).with("/login", "user" => {"gender" => "M"}) + @session.should_receive(:get).with("/login", "user" => {"gender" => "M"}) @session.chooses "Male" @session.clicks_button end @@ -66,7 +49,7 @@ describe "chooses" do EOS - @session.expects(:get).with("/login", "user" => {"gender" => "M"}) + @session.should_receive(:get).with("/login", "user" => {"gender" => "M"}) @session.chooses "Female" @session.chooses "Male" @session.clicks_button @@ -79,7 +62,7 @@ describe "chooses" do EOS - @session.expects(:post).with("/login", "first_option" => "on") + @session.should_receive(:post).with("/login", "first_option" => "on") @session.chooses "first_option" @session.clicks_button end @@ -91,7 +74,7 @@ describe "chooses" do EOS - @session.expects(:post).with("/login", "first_option" => "on") + @session.should_receive(:post).with("/login", "first_option" => "on") @session.clicks_button end end diff --git a/spec/api/clicks_button_spec.rb b/spec/api/clicks_button_spec.rb index c902b97..3978e4b 100644 --- a/spec/api/clicks_button_spec.rb +++ b/spec/api/clicks_button_spec.rb @@ -29,7 +29,7 @@ describe "clicks_button" do EOS - @session.expects(:get) + @session.should_receive(:get) @session.clicks_button end @@ -52,7 +52,7 @@ describe "clicks_button" do EOS - @session.expects(:get).with("/form1", {}) + @session.should_receive(:get).with("/form1", {}) @session.clicks_button end @@ -75,7 +75,7 @@ describe "clicks_button" do EOS - @session.expects(:get).with("/form2", {}) + @session.should_receive(:get).with("/form2", {}) @session.clicks_button "Form2" end @@ -85,7 +85,7 @@ describe "clicks_button" do EOS - @session.expects(:get).with("/login", {}) + @session.should_receive(:get).with("/login", {}) @session.clicks_button end @@ -95,7 +95,7 @@ describe "clicks_button" do EOS - @session.expects(:post) + @session.should_receive(:post) @session.clicks_button end @@ -106,7 +106,7 @@ describe "clicks_button" do EOS - @session.expects(:post).with("/login", "login" => "Login") + @session.should_receive(:post).with("/login", "login" => "Login") @session.clicks_button("Login") end @@ -117,7 +117,7 @@ describe "clicks_button" do EOS - @session.expects(:post).with("/login", {}) + @session.should_receive(:post).with("/login", {}) @session.clicks_button("Login") end @@ -128,7 +128,7 @@ describe "clicks_button" do EOS - @session.expects(:get).with("/login", "user" => {"password" => "mypass"}) + @session.should_receive(:get).with("/login", "user" => {"password" => "mypass"}) @session.clicks_button end @@ -139,7 +139,7 @@ describe "clicks_button" do EOS - @session.expects(:get).with("/login", "user" => {"email" => "test@example.com"}) + @session.should_receive(:get).with("/login", "user" => {"email" => "test@example.com"}) @session.clicks_button end @@ -150,7 +150,7 @@ describe "clicks_button" do EOS - @session.expects(:get).with("/login", "user" => {"email" => "test@example.com"}) + @session.should_receive(:get).with("/login", "user" => {"email" => "test@example.com"}) @session.clicks_button end @@ -161,7 +161,7 @@ describe "clicks_button" do EOS - @session.expects(:get).with("/login", "user" => {"tos" => "1"}) + @session.should_receive(:get).with("/login", "user" => {"tos" => "1"}) @session.clicks_button end @@ -175,7 +175,7 @@ describe "clicks_button" do EOS - @session.expects(:get).with("/login", "user" => {"gender" => "F"}) + @session.should_receive(:get).with("/login", "user" => {"gender" => "F"}) @session.clicks_button end @@ -187,7 +187,7 @@ describe "clicks_button" do EOS - @session.expects(:get).with("/login", "user" => {"tos" => "0"}) + @session.should_receive(:get).with("/login", "user" => {"tos" => "0"}) @session.clicks_button end @@ -199,7 +199,7 @@ describe "clicks_button" do EOS - @session.expects(:get).with("/login", "user" => {"tos" => "1"}) + @session.should_receive(:get).with("/login", "user" => {"tos" => "1"}) @session.clicks_button end @@ -219,7 +219,7 @@ describe "clicks_button" do EOS - @session.expects(:post).with("/login", + @session.should_receive(:post).with("/login", "options" => ["burger", "fries", "soda", "soda", "dessert"], "response" => { "choices" => [{"selected" => "one"}, {"selected" => "two"}, {"selected" => "two"}]}) @session.clicks_button @@ -232,7 +232,7 @@ describe "clicks_button" do EOS - @session.expects(:get).with("/login", {}) + @session.should_receive(:get).with("/login", {}) @session.clicks_button end @@ -243,7 +243,7 @@ describe "clicks_button" do EOS - @session.expects(:post).with("/posts", "post" => {"body" => "Post body here!"}) + @session.should_receive(:post).with("/posts", "post" => {"body" => "Post body here!"}) @session.clicks_button end @@ -257,7 +257,7 @@ describe "clicks_button" do EOS - @session.expects(:get).with("/login", "month" => "2") + @session.should_receive(:get).with("/login", "month" => "2") @session.clicks_button end @@ -271,7 +271,7 @@ describe "clicks_button" do EOS - @session.expects(:get).with("/login", "month" => "February") + @session.should_receive(:get).with("/login", "month" => "February") @session.clicks_button end @@ -285,7 +285,7 @@ describe "clicks_button" do EOS - @session.expects(:get).with("/login", "month" => "1") + @session.should_receive(:get).with("/login", "month" => "1") @session.clicks_button end @@ -297,7 +297,7 @@ describe "clicks_button" do EOS - @session.expects(:post).with("/login", "contestant" => {"scores" => {'1' => '2', '3' => '4'}}) + @session.should_receive(:post).with("/login", "contestant" => {"scores" => {'1' => '2', '3' => '4'}}) @session.clicks_button end @@ -308,7 +308,7 @@ describe "clicks_button" do EOS - @session.expects(:get).with("/login", "user" => {"email" => ""}) + @session.should_receive(:get).with("/login", "user" => {"email" => ""}) @session.clicks_button end @@ -319,7 +319,7 @@ describe "clicks_button" do EOS - @session.expects(:get).with("/login", "user" => {"email" => ""}) + @session.should_receive(:get).with("/login", "user" => {"email" => ""}) @session.clicks_button end @@ -329,7 +329,7 @@ describe "clicks_button" do EOS - @session.expects(:get) + @session.should_receive(:get) @session.clicks_button end @@ -339,7 +339,7 @@ describe "clicks_button" do EOS - @session.expects(:get) + @session.should_receive(:get) @session.clicks_button "Go" end @@ -350,7 +350,7 @@ describe "clicks_button" do EOS - @session.expects(:get).with("/login", "user" => {"email" => ""}) + @session.should_receive(:get).with("/login", "user" => {"email" => ""}) @session.clicks_button "Login" end end diff --git a/spec/api/clicks_link_spec.rb b/spec/api/clicks_link_spec.rb index 6401138..e40a863 100644 --- a/spec/api/clicks_link_spec.rb +++ b/spec/api/clicks_link_spec.rb @@ -9,7 +9,7 @@ describe "clicks_link" do @session.response_body = <<-EOS Link text EOS - @session.expects(:get).with("/page", {}) + @session.should_receive(:get).with("/page", {}) @session.clicks_link "Link text" end @@ -17,7 +17,7 @@ describe "clicks_link" do @session.response_body = <<-EOS Link text EOS - @session.expects(:get).with("/page", {}) + @session.should_receive(:get).with("/page", {}) @session.clicks_get_link "Link text" end @@ -25,7 +25,7 @@ describe "clicks_link" do @session.response_body = <<-EOS Link text EOS - @session.expects(:delete).with("/page", {}) + @session.should_receive(:delete).with("/page", {}) @session.clicks_delete_link "Link text" end @@ -33,7 +33,7 @@ describe "clicks_link" do @session.response_body = <<-EOS Link text EOS - @session.expects(:post).with("/page", {}) + @session.should_receive(:post).with("/page", {}) @session.clicks_post_link "Link text" end @@ -41,7 +41,7 @@ describe "clicks_link" do @session.response_body = <<-EOS Link text EOS - @session.expects(:put).with("/page", {}) + @session.should_receive(:put).with("/page", {}) @session.clicks_put_link "Link text" end @@ -60,7 +60,7 @@ describe "clicks_link" do f.submit(); return false;">Posts EOS - @session.expects(:post).with("/posts", "authenticity_token" => "aa79cb354597a60a3786e7e291ed4f74d77d3a62") + @session.should_receive(:post).with("/posts", "authenticity_token" => "aa79cb354597a60a3786e7e291ed4f74d77d3a62") @session.clicks_link "Posts" end @@ -79,7 +79,7 @@ describe "clicks_link" do f.submit(); return false;">Delete EOS - @session.expects(:delete).with("/posts/1", {}) + @session.should_receive(:delete).with("/posts/1", {}) @session.clicks_link "Delete" end @@ -93,7 +93,7 @@ describe "clicks_link" do f.submit(); return false;">Posts EOS - @session.expects(:post).with("/posts", {}) + @session.should_receive(:post).with("/posts", {}) @session.clicks_link "Posts" end @@ -107,7 +107,7 @@ describe "clicks_link" do f.submit(); return false;">Posts EOS - @session.expects(:get).with("/posts", {}) + @session.should_receive(:get).with("/posts", {}) @session.clicks_link "Posts", :javascript => false end @@ -126,7 +126,7 @@ describe "clicks_link" do f.submit(); return false;">Put EOS - @session.expects(:put).with("/posts", {}) + @session.should_receive(:put).with("/posts", {}) @session.clicks_link "Put" end @@ -142,7 +142,7 @@ describe "clicks_link" do @session.response_body = <<-EOS Link text EOS - @session.expects(:get).with("/page", {}) + @session.should_receive(:get).with("/page", {}) @session.clicks_link "LINK TEXT" end @@ -150,7 +150,7 @@ describe "clicks_link" do @session.response_body = <<-EOS This is some cool link text, isn't it? EOS - @session.expects(:get).with("/page", {}) + @session.should_receive(:get).with("/page", {}) @session.clicks_link "Link text" end @@ -158,24 +158,16 @@ describe "clicks_link" do @session.response_body = <<-EOS Link text EOS - @session.expects(:get).with("/page", {}) + @session.should_receive(:get).with("/page", {}) @session.clicks_link "Link text" end - it "should work with anchor titles" do - @session.response_body = <<-EOS - Link text - EOS - @session.expects(:get).with("/page", {}) - @session.clicks_link "Link title" - end - it "should match the first matching link" do @session.response_body = <<-EOS Link text Link text EOS - @session.expects(:get).with("/page1", {}) + @session.should_receive(:get).with("/page1", {}) @session.clicks_link "Link text" end @@ -185,7 +177,7 @@ describe "clicks_link" do Link EOS - @session.expects(:get).with("/page2", {}) + @session.should_receive(:get).with("/page2", {}) @session.clicks_link "Link" end @@ -197,7 +189,7 @@ describe "clicks_link" do EOS - @session.expects(:get).with("/page2", {}) + @session.should_receive(:get).with("/page2", {}) @session.clicks_link_within "#container", "Link" end @@ -205,17 +197,17 @@ describe "clicks_link" do @session.response_body = <<-EOS Jump to Section 1 EOS - # Don't know why @session.expects(:get).never doesn't work here - @session.expects(:send).with('get_via_redirect', '#section-1', {}).never + # Don't know why @session.should_receive(:get).never doesn't work here + @session.should_receive(:send).with('get_via_redirect', '#section-1', {}).never @session.clicks_link "Jump to Section 1" end it "should follow relative links" do - @session.current_page.stubs(:url).returns("/page") + @session.current_page.stub!(:url).and_return("/page") @session.response_body = <<-EOS Jump to sub page EOS - @session.expects(:get).with("/page/sub", {}) + @session.should_receive(:get).with("/page/sub", {}) @session.clicks_link "Jump to sub page" end @@ -223,16 +215,16 @@ describe "clicks_link" do @session.response_body = <<-EOS Jump to sub page EOS - @session.expects(:get).with("/page/sub", {}) + @session.should_receive(:get).with("/page/sub", {}) @session.clicks_link "Jump to sub page" end it "should follow query parameters" do - @session.current_page.stubs(:url).returns("/page") + @session.current_page.stub!(:url).and_return("/page") @session.response_body = <<-EOS Jump to foo bar EOS - @session.expects(:get).with("/page?foo=bar", {}) + @session.should_receive(:get).with("/page?foo=bar", {}) @session.clicks_link "Jump to foo bar" end end diff --git a/spec/api/fills_in_spec.rb b/spec/api/fills_in_spec.rb index 1bbb91f..8dbda73 100644 --- a/spec/api/fills_in_spec.rb +++ b/spec/api/fills_in_spec.rb @@ -13,7 +13,7 @@ describe "fills_in" do EOS - @session.expects(:post).with("/login", "user" => {"text" => "filling text area"}) + @session.should_receive(:post).with("/login", "user" => {"text" => "filling text area"}) @session.fills_in "User Text", :with => "filling text area" @session.clicks_button end @@ -25,7 +25,7 @@ describe "fills_in" do EOS - @session.expects(:post).with("/login", "user" => {"text" => "pass"}) + @session.should_receive(:post).with("/login", "user" => {"text" => "pass"}) @session.fills_in "user_text", :with => "pass" @session.clicks_button end @@ -47,7 +47,7 @@ describe "fills_in" do EOS - @session.expects(:post).with("/login", "user" => {"email" => "foo@example.com"}) + @session.should_receive(:post).with("/login", "user" => {"email" => "foo@example.com"}) @session.fills_in "user[email]", :with => "foo@example.com" @session.clicks_button end @@ -63,7 +63,7 @@ describe "fills_in" do EOS - @session.expects(:post).with("/login", "user" => {"mail1" => "", "mail2" => "value"}) + @session.should_receive(:post).with("/login", "user" => {"mail1" => "", "mail2" => "value"}) @session.fills_in "Some", :with => "value" @session.clicks_button end @@ -79,24 +79,11 @@ describe "fills_in" do EOS - @session.expects(:post).with("/login", "user" => {"mail1" => "value", "mail2" => ""}) + @session.should_receive(:post).with("/login", "user" => {"mail1" => "value", "mail2" => ""}) @session.fills_in "Some mail", :with => "value" @session.clicks_button end - it "should support unlabelled inputs" do # regression test - @session.response_body = <<-EOS - - EOS - - lambda { @session.fills_in "email", :with => "value" }.should_not raise_error - end - it "should anchor label matches to start of label" do @session.response_body = <<-EOS EOS - @session.expects(:post).with("/login", "user" => {"email" => "foo@example.com"}) + @session.should_receive(:post).with("/login", "user" => {"email" => "foo@example.com"}) @session.fills_in "Email", :with => "foo@example.com" @session.clicks_button end @@ -141,7 +128,7 @@ describe "fills_in" do EOS - @session.expects(:post).with("/login", "user" => {"email" => "foo@example.com"}) + @session.should_receive(:post).with("/login", "user" => {"email" => "foo@example.com"}) @session.fills_in "user[email]", :with => "foo@example.com" @session.clicks_button end @@ -154,7 +141,7 @@ describe "fills_in" do EOS - @session.expects(:post).with("/login", "user" => {"email" => "foo@example.com"}) + @session.should_receive(:post).with("/login", "user" => {"email" => "foo@example.com"}) @session.fills_in :email, :with => "foo@example.com" @session.clicks_button end diff --git a/spec/api/reloads_spec.rb b/spec/api/reloads_spec.rb index 129a9d8..588095d 100644 --- a/spec/api/reloads_spec.rb +++ b/spec/api/reloads_spec.rb @@ -7,7 +7,7 @@ describe "reloads" do end it "should reload the page" do - @session.expects(:get).with("/", {}).times(2) + @session.should_receive(:get).with("/", {}).twice @session.visits("/") @session.reloads end diff --git a/spec/api/save_and_open_spec.rb b/spec/api/save_and_open_spec.rb index 1a5a689..9d4a315 100644 --- a/spec/api/save_and_open_spec.rb +++ b/spec/api/save_and_open_spec.rb @@ -16,33 +16,33 @@ describe "save_and_open_page" do