Karl
2011-Feb-15 17:25 UTC
[rspec-users] TypeError: can''t convert RSpec::Mocks::Mock to Hash
In MoneyOrdersController controller: def create @money_order = current_user.money_orders.build(params[:money_order]) if @money_order.save flash.now[:msg_ok] = "Added money order for: #{number_to_currency(@money_order.amount)}" end respond_with(@money_order) end In MoneyOrdersController spec: describe "POST create" do describe "with valid params" do it "assigns a newly created money_order as @money_order" do MoneyOrder.stub(:new).with({''these'' => ''params''}) { mock_money_order(:save => true) } post :create, :money_order => {''these'' => ''params''} assigns(:money_order).should be(mock_money_order) end end It always throws this error: Failure/Error: post :create, :money_order => {''these'' => ''params''} TypeError: can''t convert RSpec::Mocks::Mock to Hash (RSpec::Mocks::Mock#to_hash gives RSpec::Mocks::Mock) I''m sure the reason is simple, why I am getting this TypeError?
Karl Smith
2011-Feb-16 22:07 UTC
[rspec-users] TypeError: can''t convert RSpec::Mocks::Mock to Hash
# controller def create @money_order = current_user.money_orders.build(params[:money_order]) if @money_order.save @money_orders = current_user.money_orders.staged flash.now[:msg_ok] = "Added money order for: #{number_to_currency(@money_order.amount)}" end respond_with(@money_order) end #controller spec describe "POST create" do describe "with valid params" do it "assigns a newly created money_order as @money_order" do MoneyOrder.stub(:new).with({''these'' => ''params''}) { mock_money_order(:save => true) } post :create, :money_order => {''these'' => ''params''} assigns(:money_order).should be(mock_money_order) end end end #returns this error Failure/Error: post :create, :money_order => {''these'' => ''params''} TypeError: can''t convert RSpec::Mocks::Mock to Hash (RSpec::Mocks::Mock#to_hash gives RSpec::Mocks::Mock) #gems rails (3.0.4) rspec (2.5.0) rspec-core (2.5.1) rspec-expectations (2.5.0) rspec-mocks (2.5.0) rspec-rails (2.5.0) ... and a few others Must be missing something simple, but I just don''t see it. What is causing the error?
Justin Ko
2011-Feb-21 00:40 UTC
[rspec-users] TypeError: can''t convert RSpec::Mocks::Mock to Hash
On Feb 15, 10:25?am, Karl <threadh... at gmail.com> wrote:> In MoneyOrdersController controller: > > def create > ? @money_order = current_user.money_orders.build(params[:money_order]) > ? if @money_order.save > ? ? flash.now[:msg_ok] = "Added money order for: > #{number_to_currency(@money_order.amount)}" > ? end > ? respond_with(@money_order) > end > > In MoneyOrdersController spec: > > describe "POST create" do > ? describe "with valid params" do > ? ? it "assigns a newly created money_order as @money_order" do > ? ? ? MoneyOrder.stub(:new).with({''these'' => ''params''}) > { mock_money_order(:save => true) } > ? ? ? post :create, :money_order => {''these'' => ''params''} > ? ? ? assigns(:money_order).should be(mock_money_order) > ? ? end > end > > It always throws this error: > > Failure/Error: post :create, :money_order => {''these'' => ''params''} > TypeError: > ? ?can''t convert RSpec::Mocks::Mock to Hash > (RSpec::Mocks::Mock#to_hash gives RSpec::Mocks::Mock) > > I''m sure the reason is simple, why I am getting this TypeError? > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-usersHmmm....what is the "mock_money_order" method doing? Care to paste it?
Lucas Renan
2011-Apr-13 16:00 UTC
[rspec-users] TypeError: can''t convert RSpec::Mocks::Mock to Hash
What''s orm you are using? activerecord? On 15 fev, 14:25, Karl <threadh... at gmail.com> wrote:> In MoneyOrdersController controller: > > def create > ? @money_order = current_user.money_orders.build(params[:money_order]) > ? if @money_order.save > ? ? flash.now[:msg_ok] = "Added money order for: > #{number_to_currency(@money_order.amount)}" > ? end > ? respond_with(@money_order) > end > > In MoneyOrdersController spec: > > describe "POST create" do > ? describe "with valid params" do > ? ? it "assigns a newly created money_order as @money_order" do > ? ? ? MoneyOrder.stub(:new).with({''these'' => ''params''}) > { mock_money_order(:save => true) } > ? ? ? post :create, :money_order => {''these'' => ''params''} > ? ? ? assigns(:money_order).should be(mock_money_order) > ? ? end > end > > It always throws this error: > > Failure/Error: post :create, :money_order => {''these'' => ''params''} > TypeError: > ? ?can''t convert RSpec::Mocks::Mock to Hash > (RSpec::Mocks::Mock#to_hashgives RSpec::Mocks::Mock) > > I''m sure the reason is simple, why I am getting this TypeError? > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users