Skip to content

Commit

Permalink
Setup rr for mocking. Convert all mock code to rr.
Browse files Browse the repository at this point in the history
This fails some tests possibly due to rr bugs. If it isn't fixed in rr 0.10.3 gem (and I don't find alternative fix) will revert this commit back to mocha.
  • Loading branch information
maxim committed Sep 10, 2009
1 parent 385a2dd commit 2a99fc0
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 38 deletions.
5 changes: 4 additions & 1 deletion configs/default/gems.yml
Expand Up @@ -67,4 +67,7 @@ ffmike-test_benchmark:
webrat:
:options:
:env: test

rr:
:options:
:version: ">=0.10.2"
:env: test
16 changes: 8 additions & 8 deletions patterns/default/test/functional/accounts_controller_test.rb
Expand Up @@ -36,9 +36,9 @@ class AccountsControllerTest < ActionController::TestCase

context "on GET to :new" do
setup do
controller.stubs(:require_no_user).returns(true)
stub(controller).require_no_user{ true }
@the_user = User.generate!
User.stubs(:new).returns(@the_user)
stub(User).new{ @the_user }
get :new
end

Expand All @@ -50,14 +50,14 @@ class AccountsControllerTest < ActionController::TestCase

context "on POST to :create" do
setup do
controller.stubs(:require_no_user).returns(true)
stub(controller).require_no_user{ true }
@the_user = User.generate!
User.stubs(:new).returns(@the_user)
stub(User).new{ @the_user }
end

context "with successful creation" do
setup do
@the_user.stubs(:save).returns(true)
stub(@the_user).save{ true }
post :create, :user => { :login => "bobby", :password => "bobby", :password_confirmation => "bobby" }
end

Expand All @@ -69,7 +69,7 @@ class AccountsControllerTest < ActionController::TestCase

context "with failed creation" do
setup do
@the_user.stubs(:save).returns(false)
stub(@the_user).save{ false }
post :create, :user => { :login => "bobby", :password => "bobby", :password_confirmation => "bobby" }
end

Expand Down Expand Up @@ -111,7 +111,7 @@ class AccountsControllerTest < ActionController::TestCase
context "on PUT to :update" do
context "with successful update" do
setup do
User.any_instance.stubs(:update_attributes).returns(true)
stub.instance_of(User).update_attributes{ true }
put :update, :user => {:login => "bill" }
end

Expand All @@ -123,7 +123,7 @@ class AccountsControllerTest < ActionController::TestCase

context "with failed update" do
setup do
User.any_instance.stubs(:update_attributes).returns(false)
stub.instance_of(User).update_attributes{ false }
put :update, :user => {:login => "bill" }
end

Expand Down
20 changes: 10 additions & 10 deletions patterns/default/test/functional/password_resets_controller_test.rb
Expand Up @@ -29,7 +29,7 @@ class PasswordResetsControllerTest < ActionController::TestCase

context "on GET to :new" do
setup do
controller.stubs(:require_no_user).returns(true)
stub(controller).require_no_user{ true }
get :new
end

Expand All @@ -40,13 +40,13 @@ class PasswordResetsControllerTest < ActionController::TestCase

context "on POST to :create" do
setup do
Notifier.stubs(:deliver_password_reset_instructions)
controller.stubs(:require_no_user).returns(true)
stub(Notifier).deliver_password_reset_instruction
stub(controller).require_no_user{ true }
end

context "with user not found" do
setup do
User.stubs(:find_by_email).returns(nil)
stub(User).find_by_email{ nil }
post :create, :email => "foo@example.com"
end

Expand All @@ -69,9 +69,9 @@ class PasswordResetsControllerTest < ActionController::TestCase

context "on GET to :edit" do
setup do
controller.stubs(:require_no_user).returns(true)
stub(controller).require_no_user{ true }
@user = User.generate!
User.stubs(:find_using_perishable_token).returns(@user)
stub(User).find_using_perishable_token{ @user }
get :edit, :id => "the token"
end

Expand All @@ -82,14 +82,14 @@ class PasswordResetsControllerTest < ActionController::TestCase

context "on PUT to :update" do
setup do
controller.stubs(:require_no_user).returns(true)
stub(controller).require_no_user{ true }
@user = User.generate!
User.stubs(:find_using_perishable_token).returns(@user)
stub(User).find_using_perishable_token{ @user }
end

context "with successful save" do
setup do
User.any_instance.stubs(:save).returns(true)
stub.instance_of(User).save{ true }
put :update, :id => "the token", :user => {:password => "the new password", :password_confirmation => "the new password"}
end

Expand All @@ -100,7 +100,7 @@ class PasswordResetsControllerTest < ActionController::TestCase

context "with failed save" do
setup do
User.any_instance.stubs(:save).returns(false)
stub.instance_of(User).save{ false }
put :update, :id => "the token", :user => {:password => "the new password", :password_confirmation => "the new password"}
end

Expand Down
Expand Up @@ -34,9 +34,9 @@ class UserSessionsControllerTest < ActionController::TestCase

context "on GET to :new" do
setup do
controller.stubs(:require_no_user).returns(true)
stub(controller).require_no_user{ true }
@the_user_session = UserSession.new
UserSession.stubs(:new).returns(@the_user_session)
stub(UserSession).new{ @the_user_session }
get :new
end

Expand All @@ -48,14 +48,14 @@ class UserSessionsControllerTest < ActionController::TestCase

context "on POST to :create" do
setup do
controller.stubs(:require_no_user).returns(true)
stub(controller).require_no_user{ true }
@the_user_session = UserSession.new
UserSession.stubs(:new).returns(@the_user_session)
stub(UserSession).new{ @the_user_session }
end

context "with successful creation" do
setup do
@the_user_session.stubs(:save).returns(true)
stub(@the_user_session).save{ true }
post :create, :user_session => { :login => "bobby", :password => "bobby" }
end

Expand All @@ -67,7 +67,7 @@ class UserSessionsControllerTest < ActionController::TestCase

context "with failed creation" do
setup do
@the_user_session.stubs(:save).returns(false)
stub(@the_user_session).save{ false }
post :create, :user_session => { :login => "bobby", :password => "bobby" }
end

Expand Down
20 changes: 10 additions & 10 deletions patterns/default/test/functional/users_controller_test.rb
Expand Up @@ -38,9 +38,9 @@ class UsersControllerTest < ActionController::TestCase

context "on GET to :index" do
setup do
controller.stubs(:admin_required).returns(true)
stub(controller).admin_required{ true }
@the_user = User.generate!
User.stubs(:all).returns([@the_user])
stub(User).all{ [@the_user] }
get :index
end

Expand All @@ -52,9 +52,9 @@ class UsersControllerTest < ActionController::TestCase

context "on GET to :new" do
setup do
controller.stubs(:require_no_user).returns(true)
stub(controller).require_no_user{ true }
@the_user = User.generate!
User.stubs(:new).returns(@the_user)
stub(User).new{ @the_user }
get :new
end

Expand All @@ -66,14 +66,14 @@ class UsersControllerTest < ActionController::TestCase

context "on POST to :create" do
setup do
controller.stubs(:require_no_user).returns(true)
stub(controller).require_no_user{ true }
@the_user = User.generate!
User.stubs(:new).returns(@the_user)
stub(User).new{ @the_user }
end

context "with successful creation" do
setup do
@the_user.stubs(:save).returns(true)
stub(@the_user).save{ true }
post :create, :user => { :login => "bobby", :password => "bobby", :password_confirmation => "bobby" }
end

Expand All @@ -85,7 +85,7 @@ class UsersControllerTest < ActionController::TestCase

context "with failed creation" do
setup do
@the_user.stubs(:save).returns(false)
stub(@the_user).save{ false }
post :create, :user => { :login => "bobby", :password => "bobby", :password_confirmation => "bobby" }
end

Expand Down Expand Up @@ -133,7 +133,7 @@ class UsersControllerTest < ActionController::TestCase
context "on PUT to :update" do
context "with successful update" do
setup do
User.any_instance.stubs(:update_attributes).returns(true)
stub.instance_of(User).update_attributes{ true }
put :update, :id => @the_user.id, :user => { :login => "bill" }
end

Expand All @@ -145,7 +145,7 @@ class UsersControllerTest < ActionController::TestCase

context "with failed update" do
setup do
User.any_instance.stubs(:update_attributes).returns(false)
stub.instance_of(User).update_attributes{ false }
put :update, :id => @the_user.id, :user => { :login => "bill" }
end

Expand Down
1 change: 1 addition & 0 deletions patterns/default/test/test_helper.rb
Expand Up @@ -19,6 +19,7 @@
class User < ActiveRecord::Base; def send_welcome_email; end; end

class ActiveSupport::TestCase
include RR::Adapters::TestUnit

self.use_transactional_fixtures = true
self.use_instantiated_fixtures = false
Expand Down
6 changes: 3 additions & 3 deletions patterns/default/test/unit/user_test.rb
Expand Up @@ -44,16 +44,16 @@ class UserTest < ActiveSupport::TestCase
context "#deliver_password_reset_instructions!" do
setup do
@user = User.generate!
Notifier.stubs(:deliver_password_reset_instructions)
stub(Notifier).deliver_password_reset_instructions
end

should "reset the perishable token" do
@user.expects(:reset_perishable_token!)
mock(@user).reset_perishable_token!
@user.deliver_password_reset_instructions!
end

should "send the reset mail" do
Notifier.expects(:deliver_password_reset_instructions).with(@user)
mock(Notifier).deliver_password_reset_instructions(@user)
@user.deliver_password_reset_instructions!
end
end
Expand Down

0 comments on commit 2a99fc0

Please sign in to comment.