Ruby on Rails Sunday, October 4, 2015

please help solve the problem. i use gem 'devise', gem 'rspec' and this
tutorial:
http://stackoverflow.com/questions/11002721/authentication-with-devise-in-rspec-tests
.i need @user output in console. emails_controller_spec.rb:

RSpec.describe EmailsController, type: :controller do
let(:valid_attributes) {
{
email: Faker::Internet.email,
description: Faker::Lorem.paragraph(7),
user_id: 1
}
}


describe "GET #index" do
login_user


it "assigns all emails as @emails" do
email = Email.create! valid_attributes
get :index
binding.pry
expect(assigns(:emails)).to eq([email])
#expect(assigns(@user)).to eq(@user)
end
end
end

spec/factories/users.rb:

FactoryGirl.define do
factory :user do
sequence(:email){ |i| "us#{i}@ad.ad" }
password 'qwertyui'
password_confirmation{ |u| u.password }
role :none
end
end
spec/support/controller_macros.rb:

module ControllerMacros
def login_user
before(:each) do
@request.env["devise.mapping"] = Devise.mappings[:user]
user = FactoryGirl.create(:user)
sign_in user
end
end
end

i user gem 'pry' for see on variables from console after run the test.
but i see follow:

kalinin@kalinin ~/rails/mailer $ rspec spec/controllers


From:
/home/kalinin/rails/mailer/spec/controllers/emails_controller_spec.rb @
line 56 :
[1] pry(#<RSpec::ExampleGroups::EmailsController::GETIndex>)> @user
=> nil
[2] pry(#<RSpec::ExampleGroups::EmailsController::GETIndex>)> user
NameError: undefined local variable or method `user' for
#<RSpec::ExampleGroups::EmailsController::GETIndex:0x00000007c4e670>
from
/home/kalinin/.rvm/gems/ruby-2.0.0-p598/gems/rspec-expectations-3.3.1/lib/rspec/matchers.rb:966:in
`method_missing'
[3] pry(#<RSpec::ExampleGroups::EmailsController::GETIndex>)> puts
page.html


=> nil

i need displays user-object or displays html-code of page. please help

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/f5b3a17fdcecbc0c1188cc24a099193e%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment