Wednesday, 15 June 2011

ruby on rails - Mock variables in view specs -



ruby on rails - Mock variables in view specs -

here's view i'm trying spec:

%h2 sign = form_for(resource, as: resource_name, url: registration_path(resource_name)) |f| = devise_error_messages! %br= f.label :email %br= f.email_field :email, autofocus: true %br= f.label :password %br= f.password_field :password, autocomplete: 'off' %br= f.label :password_confirmation %br= f.password_field :password_confirmation, autocomplete: 'off' = f.submit 'sign up' = render 'devise/shared/links'

and here's spec:

require 'spec_helper' describe 'devise/registrations/new', js: true, type: :view 'has name field' render rendered.should contain('email') end end

that returns error, undefined local variable or method 'resource'.

i expecting that. need stub variable.

putting before render function:

expect(view).to receive(:resource).and_return(stub_model(user))

results in:

error occurred in `around(:example)` hook nomethoderror: undefined method `method_removed' #<user not initialized> occurred @ /usr/local/rvm/gems/ruby-2.0.0-p0/gems/activemodel-4.1.1/lib/active_model/attribute_methods.rb:435:in `method_missing'

and

does not implement: resource

i assume means view doesn't implement resource...

ruby-on-rails rspec

No comments:

Post a Comment