EDIT Read my comment on this question.
I am very new to rails, so please carry me. I tried to set up a test for Devise using factory girls and rspec. It took me most of 2 hours, and cleaning half of the Internet is useless. Despite the fact that my problem has a lot of workloads, I just can not understand it.
This is what my / spec files look like.
GET Home Gives the correct status code
Failure/Error: sign_in user
NoMethodError:
undefined method `sign_in' for #<RSpec::Core::ExampleGroup::Nested_2:0x00000106f32558>
# ./spec/models/user_spec.rb:6:in `block (2 levels) in <top (required)>
This is the error message that I am getting while trying to run the following test:
user_spec.rb:
require 'spec_helper'
describe "GET Home" do
before do
user = FactoryGirl.create(:user)
sign_in user
end
describe "GET /Home"
it "Gives the correct status code" do
get root_path
response.status.should be(200)
end
end
in spec/factories/users.rb:
FactoryGirl.define do
factory :user do
name "Christoffer"
email "test@test2.com"
password "testtest"
password_confirmation "testtest"
end
end
And auxiliary lines are included in spec_helpers.rb
config.include FactoryGirl::Syntax::Methods
config.include Devise::TestHelpers, :type => :controller
Now, having done this, I will get the error above. Can someone explain what I'm doing wrong here? It could be something really obvious, since I did not rehearse very well in Rails.
* (, devise.rb before do):
module ValidUserRequestHelper
def sign_in_as_a_valid_user_nommels
@user ||= FactoryGirl.create :user
post_via_redirect user_session_path, 'user[email]' => @user.email, 'user[password]' => @user.password
end
end