Skip to content

Commit

Permalink
Switch from Mocha to RSpec mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
brynary committed Jul 25, 2008
1 parent af0ac09 commit 2e20267
Show file tree
Hide file tree
Showing 13 changed files with 112 additions and 141 deletions.
13 changes: 11 additions & 2 deletions lib/webrat/core/field.rb
Expand Up @@ -258,8 +258,17 @@ def to_param
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

Expand Down
12 changes: 6 additions & 6 deletions spec/api/attaches_file_spec.rb
Expand Up @@ -5,8 +5,8 @@
@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
Expand All @@ -24,7 +24,7 @@
<input type="submit" />
</form>
EOS
@session.expects(:post).with("/widgets", { "widget" => { "file" => "" } })
@session.should_receive(:post).with("/widgets", { "widget" => { "file" => "" } })
@session.clicks_button
end

Expand All @@ -36,7 +36,7 @@
<input type="submit" />
</form>
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
Expand All @@ -51,7 +51,7 @@
<input type="submit" />
</form>
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
Expand All @@ -65,7 +65,7 @@
<input type="submit" />
</form>
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
Expand Down
10 changes: 5 additions & 5 deletions spec/api/checks_spec.rb
Expand Up @@ -33,7 +33,7 @@
<input type="submit" />
</form>
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
Expand All @@ -45,7 +45,7 @@
<input type="submit" />
</form>
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
Expand All @@ -57,7 +57,7 @@
<input type="submit" />
</form>
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
Expand Down Expand Up @@ -96,7 +96,7 @@
<input type="submit" />
</form>
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
Expand All @@ -109,7 +109,7 @@
<input type="submit" />
</form>
EOS
@session.expects(:post).with("/login", {})
@session.should_receive(:post).with("/login", {})
@session.unchecks "remember_me"
@session.clicks_button
end
Expand Down
25 changes: 4 additions & 21 deletions spec/api/chooses_spec.rb
Expand Up @@ -34,24 +34,7 @@
<input type="submit" />
</form>
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
<form method="get" action="/login">
<label for="user_gender_male"><img src="male.jpg" /></label>
<input id="user_gender_male" name="user[gender]" type="radio" value="M" />
<label for="user_gender_male">Male</label>
<label for="user_gender_female"><img src="female.jpg" /></label>
<input id="user_gender_female" name="user[gender]" type="radio" value="F" />
<label for="user_gender_female">Female</label>
<input type="submit" />
</form>
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
Expand All @@ -66,7 +49,7 @@
<input type="submit" />
</form>
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
Expand All @@ -79,7 +62,7 @@
<input type="submit" />
</form>
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
Expand All @@ -91,7 +74,7 @@
<input type="submit" />
</form>
EOS
@session.expects(:post).with("/login", "first_option" => "on")
@session.should_receive(:post).with("/login", "first_option" => "on")
@session.clicks_button
end
end
52 changes: 26 additions & 26 deletions spec/api/clicks_button_spec.rb
Expand Up @@ -29,7 +29,7 @@
<input type="submit" />
</form>
EOS
@session.expects(:get)
@session.should_receive(:get)
@session.clicks_button
end

Expand All @@ -52,7 +52,7 @@
<input type="submit" />
</form>
EOS
@session.expects(:get).with("/form1", {})
@session.should_receive(:get).with("/form1", {})
@session.clicks_button
end

Expand All @@ -75,7 +75,7 @@
<input type="submit" value="Form2" />
</form>
EOS
@session.expects(:get).with("/form2", {})
@session.should_receive(:get).with("/form2", {})
@session.clicks_button "Form2"
end

Expand All @@ -85,7 +85,7 @@
<input type="submit" />
</form>
EOS
@session.expects(:get).with("/login", {})
@session.should_receive(:get).with("/login", {})
@session.clicks_button
end

Expand All @@ -95,7 +95,7 @@
<input type="submit" />
</form>
EOS
@session.expects(:post)
@session.should_receive(:post)
@session.clicks_button
end

Expand All @@ -106,7 +106,7 @@
<input type="submit" name="login" value="Login" />
</form>
EOS
@session.expects(:post).with("/login", "login" => "Login")
@session.should_receive(:post).with("/login", "login" => "Login")
@session.clicks_button("Login")
end

Expand All @@ -117,7 +117,7 @@
<input type="submit" value="Login" />
</form>
EOS
@session.expects(:post).with("/login", {})
@session.should_receive(:post).with("/login", {})
@session.clicks_button("Login")
end

Expand All @@ -128,7 +128,7 @@
<input type="submit" />
</form>
EOS
@session.expects(:get).with("/login", "user" => {"password" => "mypass"})
@session.should_receive(:get).with("/login", "user" => {"password" => "mypass"})
@session.clicks_button
end

Expand All @@ -139,7 +139,7 @@
<input type="submit" />
</form>
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

Expand All @@ -150,7 +150,7 @@
<input type="submit" />
</form>
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

Expand All @@ -161,7 +161,7 @@
<input type="submit" />
</form>
EOS
@session.expects(:get).with("/login", "user" => {"tos" => "1"})
@session.should_receive(:get).with("/login", "user" => {"tos" => "1"})
@session.clicks_button
end

Expand All @@ -175,7 +175,7 @@
<input type="submit" />
</form>
EOS
@session.expects(:get).with("/login", "user" => {"gender" => "F"})
@session.should_receive(:get).with("/login", "user" => {"gender" => "F"})
@session.clicks_button
end

Expand All @@ -187,7 +187,7 @@
<input type="submit" />
</form>
EOS
@session.expects(:get).with("/login", "user" => {"tos" => "0"})
@session.should_receive(:get).with("/login", "user" => {"tos" => "0"})
@session.clicks_button
end

Expand All @@ -199,7 +199,7 @@
<input type="submit" />
</form>
EOS
@session.expects(:get).with("/login", "user" => {"tos" => "1"})
@session.should_receive(:get).with("/login", "user" => {"tos" => "1"})
@session.clicks_button
end

Expand All @@ -219,7 +219,7 @@
<input type="submit" />
</form>
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
Expand All @@ -232,7 +232,7 @@
<input type="submit" />
</form>
EOS
@session.expects(:get).with("/login", {})
@session.should_receive(:get).with("/login", {})
@session.clicks_button
end

Expand All @@ -243,7 +243,7 @@
<input type="submit" />
</form>
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

Expand All @@ -257,7 +257,7 @@
<input type="submit" />
</form>
EOS
@session.expects(:get).with("/login", "month" => "2")
@session.should_receive(:get).with("/login", "month" => "2")
@session.clicks_button
end

Expand All @@ -271,7 +271,7 @@
<input type="submit" />
</form>
EOS
@session.expects(:get).with("/login", "month" => "February")
@session.should_receive(:get).with("/login", "month" => "February")
@session.clicks_button
end

Expand All @@ -285,7 +285,7 @@
<input type="submit" />
</form>
EOS
@session.expects(:get).with("/login", "month" => "1")
@session.should_receive(:get).with("/login", "month" => "1")
@session.clicks_button
end

Expand All @@ -297,7 +297,7 @@
<input type="submit" />
</form>
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

Expand All @@ -308,7 +308,7 @@
<input type="submit" />
</form>
EOS
@session.expects(:get).with("/login", "user" => {"email" => ""})
@session.should_receive(:get).with("/login", "user" => {"email" => ""})
@session.clicks_button
end

Expand All @@ -319,7 +319,7 @@
<button type="submit" />
</form>
EOS
@session.expects(:get).with("/login", "user" => {"email" => ""})
@session.should_receive(:get).with("/login", "user" => {"email" => ""})
@session.clicks_button
end

Expand All @@ -329,7 +329,7 @@
<input type="image" />
</form>
EOS
@session.expects(:get)
@session.should_receive(:get)
@session.clicks_button
end

Expand All @@ -339,7 +339,7 @@
<input type="image" alt="Go" />
</form>
EOS
@session.expects(:get)
@session.should_receive(:get)
@session.clicks_button "Go"
end

Expand All @@ -350,7 +350,7 @@
<button type="submit">Login</button>
</form>
EOS
@session.expects(:get).with("/login", "user" => {"email" => ""})
@session.should_receive(:get).with("/login", "user" => {"email" => ""})
@session.clicks_button "Login"
end
end

0 comments on commit 2e20267

Please sign in to comment.