I've been having trouble trying to get my test to pass. I think the issue is with my signin_path, but I can't figure out where exactly the problem is, any help would be greatly appreciated!
Here is the Failure message (it's long. sorry about that):
bundle exec rspec spec/......................FFFFFFFFFFFFFFFFFF
Failures:
1) Authentication signin page
Failure/Error: before { visit signin_path }
ActionView::Template::Error:
wrong number of arguments (0 for 1)
# ./app/helpers/sessions_helper.rb:17:in `current_user'
# ./app/helpers/sessions_helper.rb:10:in `signed_in?'
# ./app/views/layouts/_header.html.erb:9:in ` _app_views_layouts__header_html_erb__3520387809765840673_2170500560'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___1084806681328616491_2159679840'
# ./spec/requests/authentication_pages_spec.rb:8:in `block (3 levels) in <top (required)>'
2) Authentication signin page
Failure/Error: before { visit signin_path }
ActionView::Template::Error:
wrong number of arguments (0 for 1)
# ./app/helpers/sessions_helper.rb:17:in `current_user'
# ./app/helpers/sessions_helper.rb:10:in `signed_in?'
# ./app/views/layouts/_header.html.erb:9:in `_app_views_layouts__header_html_erb__3520387809765840673_2170500560'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___1084806681328616491_2159679840'
# ./spec/requests/authentication_pages_spec.rb:8:in `block (3 levels) in <top (required)>'
3) Authentication signin with invalid information
Failure/Error: before { visit signin_path }
ActionView::Template::Error:
wrong number of arguments (0 for 1)
# ./app/helpers/sessions_helper.rb:17:in `current_user'
# ./app/helpers/sessions_helper.rb:10:in `signed_in?'
# ./app/views/layouts/_header.html.erb:9:in `_app_views_layouts__header_html_erb__3520387809765840673_2170500560'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___1084806681328616491_2159679840'
# ./spec/requests/authentication_pages_spec.rb:15:in `block (3 levels) in <top (required)>'
4) Authentication signin with invalid information
Failure/Error: before { visit signin_path }
ActionView::Template::Error:
wrong number of arguments (0 for 1)
# ./app/helpers/sessions_helper.rb:17:in `current_user'
# ./app/helpers/sessions_helper.rb:10:in `signed_in?'
# ./app/views/layouts/_header.html.erb:9:in `_app_views_layouts__header_html_erb__3520387809765840673_2170500560'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___1084806681328616491_2159679840'
# ./spec/requests/authentication_pages_spec.rb:15:in `block (3 levels) in <top (required)>'
5) Authentication signin with invalid information after visiting another page
Failure/Error: before { visit signin_path }
ActionView::Template::Error:
wrong number of arguments (0 for 1)
# ./app/helpers/sessions_helper.rb:17:in `current_user'
# ./app/helpers/sessions_helper.rb:10:in `signed_in?'
# ./app/views/layouts/_header.html.erb:9:in `_app_views_layouts__header_html_erb__3520387809765840673_2170500560'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___1084806681328616491_2159679840'
# ./spec/requests/authentication_pages_spec.rb:15:in `block (3 levels) in <top (required)>'
6) Authentication signin with valid information
Failure/Error: before { visit signin_path }
ActionView::Template::Error:
wrong number of arguments (0 for 1)
# ./app/helpers/sessions_helper.rb:17:in `current_user'
# ./app/helpers/sessions_helper.rb:10:in `signed_in?'
# ./app/views/layouts/_header.html.erb:9:in `_app_views_layouts__header_html_erb__3520387809765840673_2170500560'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___1084806681328616491_2159679840'
# ./spec/requests/authentication_pages_spec.rb:15:in `block (3 levels) in <top (required)>'
7) Authentication signin with valid information
Failure/Error: before { visit signin_path }
ActionView::Template::Error:
wrong number of arguments (0 for 1)
# ./app/helpers/sessions_helper.rb:17:in `current_user'
# ./app/helpers/sessions_helper.rb:10:in `signed_in?'
# ./app/views/layouts/_header.html.erb:9:in `_app_views_layouts__header_html_erb__3520387809765840673_2170500560'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___1084806681328616491_2159679840'
# ./spec/requests/authentication_pages_spec.rb:15:in `block (3 levels) in <top (required)>'
8) Authentication signin with valid information
Failure/Error: before { visit signin_path }
ActionView::Template::Error:
wrong number of arguments (0 for 1)
# ./app/helpers/sessions_helper.rb:17:in `current_user'
# ./app/helpers/sessions_helper.rb:10:in `signed_in?'
# ./app/views/layouts/_header.html.erb:9:in `_app_views_layouts__header_html_erb__3520387809765840673_2170500560'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___1084806681328616491_2159679840'
# ./spec/requests/authentication_pages_spec.rb:15:in `block (3 levels) in <top (required)>'
9) Authentication signin with valid information
Failure/Error: before { visit signin_path }
ActionView::Template::Error:
wrong number of arguments (0 for 1)
# ./app/helpers/sessions_helper.rb:17:in `current_user'
# ./app/helpers/sessions_helper.rb:10:in `signed_in?'
# ./app/views/layouts/_header.html.erb:9:in `_app_views_layouts__header_html_erb__3520387809765840673_2170500560'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___1084806681328616491_2159679840'
# ./spec/requests/authentication_pages_spec.rb:15:in `block (3 levels) in <top (required)>'
10) Static pages Home page
Failure/Error: before { visit root_path }
ActionView::Template::Error:
wrong number of arguments (0 for 1)
# ./app/helpers/sessions_helper.rb:17:in `current_user'
# ./app/helpers/sessions_helper.rb:10:in `signed_in?'
# ./app/views/layouts/_header.html.erb:9:in `_app_views_layouts__header_html_erb__3520387809765840673_2170500560'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___1084806681328616491_2159679840'
# ./spec/requests/static_pages_spec.rb:12:in `block (3 levels) in <top (required)>'
11) Static pages Home page it should behave like all static pages
Failure/Error: before { visit root_path }
ActionView::Template::Error:
wrong number of arguments (0 for 1)
Shared Example Group: "all static pages" called from ./spec/requests/static_pages_spec.rb:16
# ./app/helpers/sessions_helper.rb:17:in `current_user'
# ./app/helpers/sessions_helper.rb:10:in `signed_in?'
# ./app/views/layouts/_header.html.erb:9:in `_app_views_layouts__header_html_erb__3520387809765840673_2170500560'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___1084806681328616491_2159679840'
# ./spec/requests/static_pages_spec.rb:12:in `block (3 levels) in <top (required)>'
12) Static pages Home page it should behave like all static pages
Failure/Error: before { visit root_path }
ActionView::Template::Error:
wrong number of arguments (0 for 1)
Shared Example Group: "all static pages" called from ./spec/requests/static_pages_spec.rb:16
# ./app/helpers/sessions_helper.rb:17:in `current_user'
# ./app/helpers/sessions_helper.rb:10:in `signed_in?'
# ./app/views/layouts/_header.html.erb:9:in `_app_views_layouts__header_html_erb__3520387809765840673_2170500560'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___1084806681328616491_2159679840'
# ./spec/requests/static_pages_spec.rb:12:in `block (3 levels) in <top (required)>'
13) User pages signup page
Failure/Error: before { visit signup_path }
ActionView::Template::Error:
wrong number of arguments (0 for 1)
# ./app/helpers/sessions_helper.rb:17:in `current_user'
# ./app/helpers/sessions_helper.rb:10:in `signed_in?'
# ./app/views/layouts/_header.html.erb:9:in `_app_views_layouts__header_html_erb__3520387809765840673_2170500560'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___1084806681328616491_2159679840'
# ./spec/requests/user_pages_spec.rb:8:in `block (3 levels) in <top (required)>'
14) User pages signup page
Failure/Error: before { visit signup_path }
ActionView::Template::Error:
wrong number of arguments (0 for 1)
# ./app/helpers/sessions_helper.rb:17:in `current_user'
# ./app/helpers/sessions_helper.rb:10:in `signed_in?'
# ./app/views/layouts/_header.html.erb:9:in `_app_views_layouts__header_html_erb__3520387809765840673_2170500560'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___1084806681328616491_2159679840'
# ./spec/requests/user_pages_spec.rb:8:in `block (3 levels) in <top (required)>'
15) User pages profile page
Failure/Error: before { visit user_path(user) }
ActionView::Template::Error:
wrong number of arguments (0 for 1)
# ./app/helpers/sessions_helper.rb:17:in `current_user'
# ./app/helpers/sessions_helper.rb:10:in `signed_in?'
# ./app/views/layouts/_header.html.erb:9:in `_app_views_layouts__header_html_erb__3520387809765840673_2170500560'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___1084806681328616491_2159679840'
# ./spec/requests/user_pages_spec.rb:17:in `block (3 levels) in <top (required)>'
16) User pages profile page
Failure/Error: before { visit user_path(user) }
ActionView::Template::Error:
wrong number of arguments (0 for 1)
# ./app/helpers/sessions_helper.rb:17:in `current_user'
# ./app/helpers/sessions_helper.rb:10:in `signed_in?'
# ./app/views/layouts/_header.html.erb:9:in `_app_views_layouts__header_html_erb__3520387809765840673_2170500560'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___1084806681328616491_2159679840'
# ./spec/requests/user_pages_spec.rb:17:in `block (3 levels) in <top (required)>'
17) User pages signup with invalid information should not create a user
Failure/Error: before { visit signup_path }
ActionView::Template::Error:
wrong number of arguments (0 for 1)
# ./app/helpers/sessions_helper.rb:17:in `current_user'
# ./app/helpers/sessions_helper.rb:10:in `signed_in?'
# ./app/views/layouts/_header.html.erb:9:in `_app_views_layouts__header_html_erb__3520387809765840673_2170500560'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___1084806681328616491_2159679840'
# ./spec/requests/user_pages_spec.rb:26:in `block (3 levels) in <top (required)>'
18) User pages signup with valid information should create a user
Failure/Error: before { visit signup_path }
ActionView::Template::Error:
wrong number of arguments (0 for 1)
# ./app/helpers/sessions_helper.rb:17:in `current_user'
# ./app/helpers/sessions_helper.rb:10:in `signed_in?'
# ./app/views/layouts/_header.html.erb:9:in `_app_views_layouts__header_html_erb__3520387809765840673_2170500560'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___1084806681328616491_2159679840'
# ./spec/requests/user_pages_spec.rb:26:in `block (3 levels) in <top (required)>'
Finished in 0.54083 seconds
40 examples, 18 failures
Failed examples:
rspec ./spec/requests/authentication_pages_spec.rb:10 # Authentication signin page
rspec ./spec/requests/authentication_pages_spec.rb:11 # Authentication signin page
rspec ./spec/requests/authentication_pages_spec.rb:20 # Authentication signin with invalid information
rspec ./spec/requests/authentication_pages_spec.rb:21 # Authentication signin with invalid information
rspec ./spec/requests/authentication_pages_spec.rb:25 # Authentication signin with invalid information after visiting another page
rspec ./spec/requests/authentication_pages_spec.rb:37 # Authentication signin with valid information
rspec ./spec/requests/authentication_pages_spec.rb:38 # Authentication signin with valid information
rspec ./spec/requests/authentication_pages_spec.rb:39 # Authentication signin with valid information
rspec ./spec/requests/authentication_pages_spec.rb:40 # Authentication signin with valid information
rspec ./spec/requests/static_pages_spec.rb:17 # Static pages Home page
rspec ./spec/requests/static_pages_spec.rb:7 # Static pages Home page it should behave like all static pages
rspec ./spec/requests/static_pages_spec.rb:8 # Static pages Home page it should behave like all static pages
rspec ./spec/requests/user_pages_spec.rb:10 # User pages signup page
rspec ./spec/requests/user_pages_spec.rb:11 # User pages signup page
rspec ./spec/requests/user_pages_spec.rb:19 # User pages profile page
rspec ./spec/requests/user_pages_spec.rb:20 # User pages profile page
rspec ./spec/requests/user_pages_spec.rb:31 # User pages signup with invalid information should not create a user
rspec ./spec/requests/user_pages_spec.rb:47 # User pages signup with valid information should create a user
Here is the authentication_pages_spec.rb
require 'spec_helper'
describe "Authentication" do
subject { page }
describe "signin page" do
before { visit signin_path }
it { should have_selector('h1', text: 'Sign in') }
it { should have_selector('title', text: 'Sign in') }
end
describe "signin" do
before { visit signin_path }
describe "with invalid information" do
before { click_button "Sign in"}
it { should have_selector('title', text: 'Sign in') }
it { should have_selector('div.alert.alert-error', text: 'Invalid') }
describe "after visiting another page" do
before { click_link "Home" }
it { should_not have_selector('div.alert.alert-error') }
end
end
describe "with valid information" do
let(:user) { FactoryGirl.create(:user) }
before do
fill_in "Email", with: user.email
fill_in "Password", with: user.password
click_button "Sign in"
end
it { should have_selector('title', text: user.name) }
it { should have_link('Profile', href: user_path(user)) }
it { should have_link('Sign out', href: signout_path) }
it { should_not have_link('Sign in', href: signin_path) }
end
end
end
Here is the static_pages_spec.rb
require 'spec_helper'
describe "Static pages" do
subject { page }
shared_examples_for "all static pages" do
it { should have_selector('h1', text: heading) }
it { should have_selector('title', text: full_title(page_title)) }
end
describe "Home page" do
before { visit root_path }
let(:heading) { 'Sample App' }
let(:page_title) { '' }
it_should_behave_like "all static pages"
it { should_not have_selector 'title', text: '| Home' }
end
describe "Help page" do
before { visit help_path }
let(:heading) { 'Help' }
let(:page_title) { 'Help' }
end
describe "About Us page" do
before { visit about_path }
let(:heading) { 'About Us' }
let(:page_title) { 'About Us' }
end
describe "Contact page" do
before { visit contact_path }
let(:heading) { 'Contact' }
let(:page_title) { 'Contact' }
end
end
Here is the user_pages_spec.rb:
require 'spec_helper'
describe "User pages" do
subject { page }
describe "signup page" do
before { visit signup_path }
it { should have_selector('h1', text: 'Sign up') }
it { should have_selector('title', text: full_title('Sign up')) }
end
describe "profile page" do
let(:user) { FactoryGirl.create(:user) }
#Code to make a user variable
before { visit user_path(user) }
it { should have_selector('h1', text: user.name) }
it { should have_selector('title', text: user.name) }
end
describe "signup" do
before { visit signup_path }
let(:submit) { "Create my account" }
describe "with invalid information" do
it "should not create a user" do
expect { click_button submit }.not_to change(User, :count)
end
end
describe "with valid information" do
before do
fill_in "Name", with: "Example User"
fill_in "Email", with: "user#example.com"
fill_in "Password", with: "foobar"
fill_in "Confirmation", with: "foobar"
end
it "should create a user" do
expect { click_button submit }.to change(User, :count).by(1)
end
end
end
end
Here is the session_helper.rb:
module SessionsHelper
require 'sessions_helper'
def sign_in(user)
cookies.permanent[:remember_token] = user.remember_token
self.current_user = user
end
def signed_in?
!current_user.nil?
end
def current_user=(user)
#current_user = user
end
def current_user(user)
#current_user ||= User.find_by_remember_token(cookies[:remember_token])
end
end
I haven't figured out how to get HTML to post, but if it would be helpful to see the applicaiton.html.erb and the _header.html.erb, just let me know and I will keep trying. Any thoughts would be greatly appreciated! thanks!
The last method in your SessionsHelper module, current_user, doesn't need to take an argument user. This is why you see the error "wrong number of arguments (0 for 1)."
Related
I am currently working on Chapter 8 of Michael Hartl's Ruby on Rails tutorial. I encountered a problem with my tests failing and tried to solve this myself, but I realize it's useless, so I have to ask here. Here is the error message I'm getting.
Failures:
1) Authentication signin with invalid information after visiting another page
Failure/Error: it { should_not have_selector('div.alert.alert-error') }
expected #has_selector?("div.alert.alert-error") to return false, got true
# ./spec/requests/authentication_pages_spec.rb:18:in `block (5 levels) in <top (required)>'
2) Authentication signin with valid information
Failure/Error: click_button "Sign in"
NoMethodError:
undefined method `sign_in' for #<SessionsController:0x007f8dbc9d5868>
# ./app/controllers/sessions_controller.rb:8:in `create'
# ./spec/requests/authentication_pages_spec.rb:27:in `block (4 levels) in <top (required)>'
3) Authentication signin with valid information
Failure/Error: click_button "Sign in"
NoMethodError:
undefined method `sign_in' for #<SessionsController:0x007f8dbfdf53a0>
# ./app/controllers/sessions_controller.rb:8:in `create'
# ./spec/requests/authentication_pages_spec.rb:27:in `block (4 levels) in <top (required)>'
4) Authentication signin with valid information
Failure/Error: click_button "Sign in"
NoMethodError:
undefined method `sign_in' for #<SessionsController:0x007f8dbfcf5ea0>
# ./app/controllers/sessions_controller.rb:8:in `create'
# ./spec/requests/authentication_pages_spec.rb:27:in `block (4 levels) in <top (required)>'
5) Authentication signin with valid information
Failure/Error: click_button "Sign in"
NoMethodError:
undefined method `sign_in' for #<SessionsController:0x007f8dbfc0ccc8>
# ./app/controllers/sessions_controller.rb:8:in `create'
# ./spec/requests/authentication_pages_spec.rb:27:in `block (4 levels) in <top (required)>'
6) User pages signup with valid information should create a user
Failure/Error: fill_in "Confirmation", with: "foobar"
Capybara::ElementNotFound:
Unable to find field "Confirmation"
# ./spec/requests/user_pages_spec.rb:24:in `block (4 levels) in <top (required)>'
Finished in 0.60967 seconds
41 examples, 6 failures
Failed examples:
rspec ./spec/requests/authentication_pages_spec.rb:18 # Authentication signin with invalid information after visiting another page
rspec ./spec/requests/authentication_pages_spec.rb:30 # Authentication signin with valid information
rspec ./spec/requests/authentication_pages_spec.rb:32 # Authentication signin with valid information
rspec ./spec/requests/authentication_pages_spec.rb:31 # Authentication signin with valid information
rspec ./spec/requests/authentication_pages_spec.rb:33 # Authentication signin with valid information
rspec ./spec/requests/user_pages_spec.rb:27 # User pages signup with valid information should create a user
Randomized with seed 17229
Here is my authentication pages spec file
require 'spec_helper'
describe "Authentication" do
subject { page }
describe "signin" do
before { visit signin_path }
describe "with invalid information" do
before { click_button "Sign in" }
it { should have_title('Sign in') }
it { should have_selector('div.alert.alert-error') }
describe "after visiting another page" do
before { click_link "Home" }
it { should_not have_selector('div.alert.alert-error') }
end
end
describe "with valid information" do
let(:user) { FactoryGirl.create(:user) }
before do
fill_in "Email", with: user.email.upcase
fill_in "Password", with: user.password
click_button "Sign in"
end
it { should have_title(user.name) }
it { should have_link('Profile', href: user_path(user)) }
it { should have_link('Sign out', href: signout_path) }
it { should_not have_link('Sign in', href: signin_path) }
end
end
end
Here is my sessions_controller.rb file
class SessionsController < ApplicationController
def new
end
def create
user = User.find_by(email: params[:session][:email].downcase)
if user && user.authenticate(params[:session][:password])
sign_in user
redirect_to user
else
# Create an error message and re-render the signin form
flash.now[:error] = 'Invalid email/password combination'
render 'new'
end
end
def destroy
end
end
The main failure I'm trying to solve, that should be green is 1. I passed the flash.now hash to indicate that I want the flash to disappear after a second request, but rspec says no.
I'm stumped as to what the problem is. Any help would be greatly appreciated
RSpec tells you that method sign_in does not exists. If you look at the chapter 8.2.2 you will find a helper with this method.
#app/helpers/sessions_helper.rb
module SessionsHelper
def sign_in(user)
remember_token = User.new_remember_token
cookies.permanent[:remember_token] = remember_token
user.update_attribute(:remember_token, User.digest(remember_token))
self.current_user = user
end
end
Can anyone who has done this exercises help me out?
It's my first time using this programming language and not much to this, but I need to finish well until chapter 10 that is a final evaluation.
1) User pages edit with valid information
Failure/Error: describe "page" do
NoMethodError:
undefined method `describe' for #<RSpec::Core::ExampleGroup::Nested_5::Nested_5::Nested_1:0xc283f8c>
# ./spec/requests/user_pages_spec.rb:87:in `block (3 levels) in <top (required)>'
2) User pages edit with valid information
Failure/Error: describe "page" do
NoMethodError:
undefined method `describe' for #<RSpec::Core::ExampleGroup::Nested_5::Nested_5::Nested_1:0xb67b1cc>
# ./spec/requests/user_pages_spec.rb:87:in `block (3 levels) in <top (required)>'
3) User pages edit with valid information
Failure/Error: describe "page" do
NoMethodError:
undefined method `describe' for #<RSpec::Core::ExampleGroup::Nested_5::Nested_5::Nested_1:0xc224244>
# ./spec/requests/user_pages_spec.rb:87:in `block (3 levels) in <top (required)>'
4) User pages edit with valid information
Failure/Error: describe "page" do
NoMethodError:
undefined method `describe' for #<RSpec::Core::ExampleGroup::Nested_5::Nested_5::Nested_1:0xc562690>
# ./spec/requests/user_pages_spec.rb:87:in `block (3 levels) in <top (required)>'
5) User pages edit with valid information
Failure/Error: describe "page" do
NoMethodError:
undefined method `describe' for #<RSpec::Core::ExampleGroup::Nested_5::Nested_5::Nested_1:0xc0559a4>
# ./spec/requests/user_pages_spec.rb:87:in `block (3 levels) in <top (required)>'
6) User pages index
Failure/Error: visit users_path
ActionView::Template::Error:
undefined method `each' for nil:NilClass
# ./app/views/users/index.html.erb:5:in `_app_views_users_index_html_erb__615083638_97671840'
# ./spec/requests/user_pages_spec.rb:12:in `block (3 levels) in <top (required)>'
7) User pages index
Failure/Error: visit users_path
ActionView::Template::Error:
undefined method `each' for nil:NilClass
# ./app/views/users/index.html.erb:5:in `_app_views_users_index_html_erb__615083638_97671840'
# ./spec/requests/user_pages_spec.rb:12:in `block (3 levels) in <top (required)>'
8) User pages index should list each user
Failure/Error: visit users_path
ActionView::Template::Error:
undefined method `each' for nil:NilClass
# ./app/views/users/index.html.erb:5:in `_app_views_users_index_html_erb__615083638_97671840'
# ./spec/requests/user_pages_spec.rb:12:in `block (3 levels) in <top (required)>'
9) Authentication authorization after signing in should render the desired protected page
Failure/Error: expect(page).to have_title('Edit user')
expected #has_title?("Edit user") to return true, got false
# ./spec/requests/authentication_pages_spec.rb:84:in `block (4 levels) in <top (required)>'
Finished in 2.25 seconds
72 examples, 9 failures
Failed examples:
rspec ./spec/requests/user_pages_spec.rb:114 # User pages edit with valid information
rspec ./spec/requests/user_pages_spec.rb:115 # User pages edit with valid information
rspec ./spec/requests/user_pages_spec.rb:112 # User pages edit with valid information
rspec ./spec/requests/user_pages_spec.rb:113 # User pages edit with valid information
rspec ./spec/requests/user_pages_spec.rb:111 # User pages edit with valid information
rspec ./spec/requests/user_pages_spec.rb:15 # User pages index
rspec ./spec/requests/user_pages_spec.rb:16 # User pages index
rspec ./spec/requests/user_pages_spec.rb:18 # User pages index should list each user
rspec ./spec/requests/authentication_pages_spec.rb:83 # Authentication authorization after signing in should render the desired protected page
Edit
Here is my code:
require 'spec_helper'
describe "User pages" do
subject { page }
describe "index" do
before do
sign_in FactoryGirl.create(:user)
FactoryGirl.create(:user, name: "Bob", email: "bob#example.com")
FactoryGirl.create(:user, name: "Ben", email: "ben#example.com")
visit users_path
end
it { should have_title('All users') }
it { should have_content('All users') }
it "should list each user" do
User.all.each do |user|
expect(page).to have_selector('li', text: user.name)
end
end
end
describe "profile page" do
let(:user) { FactoryGirl.create(:user) }
before { visit user_path(user) }
it { should have_content(user.name) }
it { should have_title(user.name) }
end
describe "signup page" do
before { visit signup_path }
it { should have_content('Sign up') }
it { should have_title(full_title('Sign up')) }
end
describe "signup" do
before { visit signup_path }
let(:submit) { "Create my account" }
describe "with invalid information" do
it "should not create a user" do
expect { click_button submit }.not_to change(User, :count)
end
describe "after submission" do
before { click_button submit }
it { should have_title('Sign up') }
it { should have_content('error') }
end
end
describe "with valid information" do
before do
fill_in "Name", with: "Example User"
fill_in "Email", with: "user#example.com"
fill_in "Password", with: "foobar"
fill_in "Confirmation", with: "foobar"
end
it "should create a user" do
expect { click_button submit }.to change(User, :count).by(1)
end
describe "after saving the user" do
before { click_button submit }
let(:user) { User.find_by(email: 'user#example.com') }
it { should have_link('Sign out') }
it { should have_title(user.name) }
it { should have_selector('div.alert.alert-success', text: 'Welcome') }
end
end
end
describe "edit" do
let(:user) { FactoryGirl.create(:user) }
before do
sign_in user
visit edit_user_path(user)
describe "page" do
it { should have_content("Update your profile") }
it { should have_title("Edit user") }
it { should have_link('change', href: 'http://gravatar.com/emails') }
end
describe "with invalid information" do
before { click_button "Save changes" }
it { should have_content('error') }
end
end
describe "with valid information" do
let(:new_name) { "New Name" }
let(:new_email) { "new#example.com" }
before do
fill_in "Name", with: new_name
fill_in "Email", with: new_email
fill_in "Password", with: user.password
fill_in "Confirm Password", with: user.password
click_button "Save changes"
end
it { should have_title(new_name) }
it { should have_selector('div.alert.alert-success') }
it { should have_link('Sign out', href: signout_path) }
specify { expect(user.reload.name).to eq new_name }
specify { expect(user.reload.email).to eq new_email }
end
end
end
If your code is formatted like this:
describe "edit" do
let(:user) { FactoryGirl.create(:user) }
before do
sign_in user
visit edit_user_path(user)
describe "page" do
it { should have_content("Update your profile") }
it { should have_title("Edit user") }
it { should have_link('change', href: 'http://gravatar.com/emails') }
end
I can see that it is probably broken without reading any of your code.
Are all your code blocks properly closed? Does not look so!
In addition to the unclosed blocks that phoet pointed out, which are causing your "undefined method describe" errors, you're getting errors in /app/views/users/index.html.erb line 5. The error is undefined method `each' for nil:NilClass which means there's a variable on that line that you're doing variable.each with, but you're either not setting that variable or when you're setting it, it's getting set to nil.
In general, the way for you to successfully get through this is to read the error messages and try to fix what they're complaining about. If you search for each error message individually, you'll find stack overflow questions about the specific issue that will help you.
I'm using ruby 1.8.7 on mac osx10.8. I have no idea what these errors mean. I am currently at the end of chapter 9 of the ruby on rails tutorial. Any help is greatly appreciated!
1) Authentication signin with invalid information
Failure/Error: before { click_button "Sign in" }
NoMethodError:
undefined method `[]' for nil:NilClass
# ./app/controllers/sessions_controller.rb:8:in `create'
# (eval):2:in `send'
# (eval):2:in `click_button'
# ./spec/requests/authentication_pages_spec.rb:21
2) Authentication signin with invalid information
Failure/Error: before { click_button "Sign in" }
NoMethodError:
undefined method `[]' for nil:NilClass
# ./app/controllers/sessions_controller.rb:8:in `create'
# (eval):2:in `send'
# (eval):2:in `click_button'
# ./spec/requests/authentication_pages_spec.rb:21
3) Authentication signin with invalid information after visiting another page
Failure/Error: before { click_button "Sign in" }
NoMethodError:
undefined method `[]' for nil:NilClass
# ./app/controllers/sessions_controller.rb:8:in `create'
# (eval):2:in `send'
# (eval):2:in `click_button'
# ./spec/requests/authentication_pages_spec.rb:21
4) Authentication signin with valid information
Failure/Error: before { sign_in user }
NoMethodError:
undefined method `[]' for nil:NilClass
# ./app/controllers/sessions_controller.rb:8:in `create'
# (eval):2:in `send'
# (eval):2:in `click_button'
# ./spec/support/utilities.rb:13:in `sign_in'
# ./spec/requests/authentication_pages_spec.rb:34
5) Authentication signin with valid information
Failure/Error: before { sign_in user }
NoMethodError:
undefined method `[]' for nil:NilClass
# ./app/controllers/sessions_controller.rb:8:in `create'
# (eval):2:in `send'
# (eval):2:in `click_button'
# ./spec/support/utilities.rb:13:in `sign_in'
# ./spec/requests/authentication_pages_spec.rb:34
6) Authentication signin with valid information
Failure/Error: before { sign_in user }
NoMethodError:
undefined method `[]' for nil:NilClass
# ./app/controllers/sessions_controller.rb:8:in `create'
# (eval):2:in `send'
# (eval):2:in `click_button'
# ./spec/support/utilities.rb:13:in `sign_in'
# ./spec/requests/authentication_pages_spec.rb:34
7) Authentication signin with valid information
Failure/Error: before { sign_in user }
NoMethodError:
undefined method `[]' for nil:NilClass
# ./app/controllers/sessions_controller.rb:8:in `create'
# (eval):2:in `send'
# (eval):2:in `click_button'
# ./spec/support/utilities.rb:13:in `sign_in'
# ./spec/requests/authentication_pages_spec.rb:34
8) Authentication signin with valid information
Failure/Error: before { sign_in user }
NoMethodError:
undefined method `[]' for nil:NilClass
# ./app/controllers/sessions_controller.rb:8:in `create'
# (eval):2:in `send'
# (eval):2:in `click_button'
# ./spec/support/utilities.rb:13:in `sign_in'
# ./spec/requests/authentication_pages_spec.rb:34
9) Authentication signin with valid information
Failure/Error: before { sign_in user }
NoMethodError:
undefined method `[]' for nil:NilClass
# ./app/controllers/sessions_controller.rb:8:in `create'
# (eval):2:in `send'
# (eval):2:in `click_button'
# ./spec/support/utilities.rb:13:in `sign_in'
# ./spec/requests/authentication_pages_spec.rb:34
10) Authentication signin with valid information followed by signout
Failure/Error: before { sign_in user }
NoMethodError:
undefined method `[]' for nil:NilClass
# ./app/controllers/sessions_controller.rb:8:in `create'
# (eval):2:in `send'
# (eval):2:in `click_button'
# ./spec/support/utilities.rb:13:in `sign_in'
# ./spec/requests/authentication_pages_spec.rb:34
11) Authentication authorization for non-signed-in users when attempting to visit a protected page after signing in should render the desired protected page
Failure/Error: click_button "Sign in"
NoMethodError:
undefined method `[]' for nil:NilClass
# ./app/controllers/sessions_controller.rb:8:in `create'
# (eval):2:in `send'
# (eval):2:in `click_button'
# ./spec/requests/authentication_pages_spec.rb:60
12) Authentication authorization for non-signed-in users when attempting to visit a protected page after signing in when signing in again should render the default (profile) page
Failure/Error: click_button "Sign in"
NoMethodError:
undefined method `[]' for nil:NilClass
# ./app/controllers/sessions_controller.rb:8:in `create'
# (eval):2:in `send'
# (eval):2:in `click_button'
# ./spec/requests/authentication_pages_spec.rb:60
13) Authentication authorization for non-signed-in users as wrong user visiting Users#edit page
Failure/Error: before { sign_in user }
NoMethodError:
undefined method `[]' for nil:NilClass
# ./app/controllers/sessions_controller.rb:8:in `create'
# (eval):2:in `send'
# (eval):2:in `click_button'
# ./spec/support/utilities.rb:13:in `sign_in'
# ./spec/requests/authentication_pages_spec.rb:106
14) Authentication authorization for non-signed-in users as wrong user submitting a PUT request to the Users#update action
Failure/Error: before { sign_in user }
NoMethodError:
undefined method `[]' for nil:NilClass
# ./app/controllers/sessions_controller.rb:8:in `create'
# (eval):2:in `send'
# (eval):2:in `click_button'
# ./spec/support/utilities.rb:13:in `sign_in'
# ./spec/requests/authentication_pages_spec.rb:106
15) User pages index
Failure/Error: sign_in user
NoMethodError:
undefined method `[]' for nil:NilClass
# ./app/controllers/sessions_controller.rb:8:in `create'
# (eval):2:in `send'
# (eval):2:in `click_button'
# ./spec/support/utilities.rb:13:in `sign_in'
# ./spec/requests/user_pages_spec.rb:12
16) User pages index
Failure/Error: sign_in user
NoMethodError:
undefined method `[]' for nil:NilClass
# ./app/controllers/sessions_controller.rb:8:in `create'
# (eval):2:in `send'
# (eval):2:in `click_button'
# ./spec/support/utilities.rb:13:in `sign_in'
# ./spec/requests/user_pages_spec.rb:12
17) User pages index pagination
Failure/Error: sign_in user
NoMethodError:
undefined method `[]' for nil:NilClass
# ./app/controllers/sessions_controller.rb:8:in `create'
# (eval):2:in `send'
# (eval):2:in `click_button'
# ./spec/support/utilities.rb:13:in `sign_in'
# ./spec/requests/user_pages_spec.rb:12
18) User pages index pagination should list each user
Failure/Error: sign_in user
NoMethodError:
undefined method `[]' for nil:NilClass
# ./app/controllers/sessions_controller.rb:8:in `create'
# (eval):2:in `send'
# (eval):2:in `click_button'
# ./spec/support/utilities.rb:13:in `sign_in'
# ./spec/requests/user_pages_spec.rb:12
19) User pages signup page with valid information edit page
Failure/Error: sign_in user
NoMethodError:
undefined method `[]' for nil:NilClass
# ./app/controllers/sessions_controller.rb:8:in `create'
# (eval):2:in `send'
# (eval):2:in `click_button'
# ./spec/support/utilities.rb:13:in `sign_in'
# ./spec/requests/user_pages_spec.rb:78
20) User pages signup page with valid information edit page
Failure/Error: sign_in user
NoMethodError:
undefined method `[]' for nil:NilClass
# ./app/controllers/sessions_controller.rb:8:in `create'
# (eval):2:in `send'
# (eval):2:in `click_button'
# ./spec/support/utilities.rb:13:in `sign_in'
# ./spec/requests/user_pages_spec.rb:78
21) User pages signup page with valid information edit page
Failure/Error: sign_in user
NoMethodError:
undefined method `[]' for nil:NilClass
# ./app/controllers/sessions_controller.rb:8:in `create'
# (eval):2:in `send'
# (eval):2:in `click_button'
# ./spec/support/utilities.rb:13:in `sign_in'
# ./spec/requests/user_pages_spec.rb:78
22) User pages signup page with valid information edit with invalid information
Failure/Error: sign_in user
NoMethodError:
undefined method `[]' for nil:NilClass
# ./app/controllers/sessions_controller.rb:8:in `create'
# (eval):2:in `send'
# (eval):2:in `click_button'
# ./spec/support/utilities.rb:13:in `sign_in'
# ./spec/requests/user_pages_spec.rb:78
23) User pages signup page with valid information edit with valid information
Failure/Error: sign_in user
NoMethodError:
undefined method `[]' for nil:NilClass
# ./app/controllers/sessions_controller.rb:8:in `create'
# (eval):2:in `send'
# (eval):2:in `click_button'
# ./spec/support/utilities.rb:13:in `sign_in'
# ./spec/requests/user_pages_spec.rb:78
24) User pages signup page with valid information edit with valid information
Failure/Error: sign_in user
NoMethodError:
undefined method `[]' for nil:NilClass
# ./app/controllers/sessions_controller.rb:8:in `create'
# (eval):2:in `send'
# (eval):2:in `click_button'
# ./spec/support/utilities.rb:13:in `sign_in'
# ./spec/requests/user_pages_spec.rb:78
25) User pages signup page with valid information edit with valid information
Failure/Error: sign_in user
NoMethodError:
undefined method `[]' for nil:NilClass
# ./app/controllers/sessions_controller.rb:8:in `create'
# (eval):2:in `send'
# (eval):2:in `click_button'
# ./spec/support/utilities.rb:13:in `sign_in'
# ./spec/requests/user_pages_spec.rb:78
26) User pages signup page with valid information edit with valid information
Failure/Error: sign_in user
NoMethodError:
undefined method `[]' for nil:NilClass
# ./app/controllers/sessions_controller.rb:8:in `create'
# (eval):2:in `send'
# (eval):2:in `click_button'
# ./spec/support/utilities.rb:13:in `sign_in'
# ./spec/requests/user_pages_spec.rb:78
27) User pages signup page with valid information edit with valid information
Failure/Error: sign_in user
NoMethodError:
undefined method `[]' for nil:NilClass
# ./app/controllers/sessions_controller.rb:8:in `create'
# (eval):2:in `send'
# (eval):2:in `click_button'
# ./spec/support/utilities.rb:13:in `sign_in'
# ./spec/requests/user_pages_spec.rb:78
my sessions controller:
class SessionsController < ApplicationController
def new
#title = "Sign in"
end
def create
user = User.find_by_email(params[:session][:email].downcase)
if user && user.authenticate(params[:session][:password])
sign_in user
redirect_back_or user
else
flash.now[:error] = 'Invalid email/password combination'
render 'new'
end
end
def destroy
sign_out
redirect_to root_path
end
end
My User_pages_spec
require 'spec_helper'
describe "User pages" do
subject { page }
describe "index" do
let(:user) { FactoryGirl.create(:user) }
before(:each) do
sign_in user
visit users_path
end
it { should have_selector('title', :text => 'All users') }
it { should have_selector('h1', :text => 'All users') }
describe "pagination" do
before(:all) { 30.times { FactoryGirl.create(:user) } }
after(:all) { User.delete_all }
it { should have_selector('div.pagination') }
it "should list each user" do
User.paginate(:page => 1).each do |user|
page.should have_selector('li', :text => user.name)
end
end
end
end
describe "signup page" do
before { visit signup_path }
let(:submit) { "Create my account" }
it { should have_selector('h1', :text => 'Sign up') }
it { should have_selector('title', :text => full_title('Sign up')) }
describe "with invalid information" do
it "should not create a user" do
expect { click_button submit }.not_to change(User, :count)
end
describe "after submission" do
before { click_button submit }
it { should have_selector('title', :text => 'Sign up') }
it { should have_content('error') }
end
end
describe "with valid information" do
before do
fill_in "Name", :with => "Example User"
fill_in "Email", :with => "user#example.com"
fill_in "Password", :with => "foobar"
fill_in "Confirmation", :with => "foobar"
end
it "should create a user" do
expect { click_button submit }.to change(User, :count).by(1)
end
describe "after saving the user" do
before { click_button submit }
let(:user) { User.find_by_email('user#example.com') }
it { should have_selector('title', :text => user.name) }
it { should have_selector('div.alert.alert-success', :text => 'Welcome') }
end
describe "edit" do
let(:user) { FactoryGirl.create(:user) }
before do
sign_in user
visit edit_user_path(user)
end
describe "page" do
it { should have_selector('h1', :text => "Update your profile") }
it { should have_selector('title', :text => "Edit user") }
it { should have_link('change', :href => 'http://gravatar.com/emails') }
end
describe "with invalid information" do
before { click_button "Save changes" }
it { should have_content('error') }
end
describe "with valid information" do
let(:new_name) { "New Name" }
let(:new_email) { "new#example.com" }
before do
fill_in "Name", :with => new_name
fill_in "Email", :with => new_email
fill_in "Password", :with => user.password
fill_in "Confirm Password", :with => user.password
click_button "Save changes"
end
it { should have_selector('title', :text => new_name) }
it { should have_selector('div.alert.alert-success') }
it { should have_link('Sign out', :href => signout_path) }
specify { user.reload.name.should == new_name }
specify { user.reload.email.should == new_email }
end
end
end
end
end
My authentication_pages_spec:
require 'spec_helper'
describe "Authentication" do
subject { page }
describe "signin page" do
before { visit signin_path }
it { should have_selector('h1', :text => 'Sign in') }
it { should have_selector('h1','title', :text => 'Sign in') }
end
describe "signin" do
before { visit signin_path }
describe "with invalid information" do
before { click_button "Sign in" }
it { should have_selector('h1', 'title', :text => 'Sign in') }
it { should have_error_message }
describe "after visiting another page" do
before { click_link "Home" }
it { should_not have_error_message }
end
end
describe "with valid information" do
let(:user) { FactoryGirl.create(:user) }
before { sign_in user }
it { should have_selector('title', :text => user.name) }
it { should have_link('Profile', :href => user_path(user)) }
it { should have_link('Sign out', :href => signout_path) }
it { should have_link('Settings', :href => edit_user_path(user)) }
it { should have_link('Users', :href => users_path) }
it { should_not have_link('Sign in', :href => signin_path) }
describe "followed by signout" do
before { click_link "Sign out" }
it { should have_link('Sign in') }
end
end
end
describe "authorization" do
describe "for non-signed-in users" do
let(:user) { FactoryGirl.create(:user) }
describe "when attempting to visit a protected page" do
before do
visit edit_user_path(user)
fill_in "Email", :with => user.email
fill_in "Password", :with => user.password
click_button "Sign in"
end
describe "after signing in" do
it "should render the desired protected page" do
page.should have_selector('title', :text => 'Edit user')
end
describe "when signing in again" do
before do
click_link "Sign out"
click_link "Sign in"
fill_in "Email", :with => user.email
fill_in "Password", :with => user.password
click_button "Sign in"
end
it "should render the default (profile) page" do
page.should have_selector('title', :text => user.name)
end
end
end
end
describe "in the Users controller" do
describe "visiting the edit page" do
before { visit edit_user_path(user) }
it { should have_selector('title', :text => 'Sign in') }
it { should have_selector('div.alert.alert-notice') }
end
describe "submitting to the update action" do
before { put user_path(user) }
specify { response.should redirect_to(signin_path) }
end
describe "visiting the user index" do
before { visit users_path }
it { should have_selector('title', :text => 'Sign in') }
end
end
describe "as wrong user" do
let(:user) { FactoryGirl.create(:user) }
let(:wrong_user) { FactoryGirl.create(:user, :email => "wrong#example.com") }
before { sign_in user }
describe "visiting Users#edit page" do
before { visit edit_user_path(wrong_user) }
it { should_not have_selector('h1', 'title', :text => full_title('Edit user')) }
end
describe "submitting a PUT request to the Users#update action" do
before { put user_path(wrong_user) }
specify { response.should redirect_to(root_url) }
end
end
end
end
end
new,html.erb:
<% provide(:title, "Sign in") %>
<h1>Sign in</h1>
<div class="row">
<div class="span6 offset3">
<%= form_tag sessions_path do %>
<%= label_tag :email %>
<%= text_field_tag :email, params[:email] %>
<%= label_tag :password %>
<%= password_field_tag :password %>
<%= submit_tag "Sign in", :class => "btn btn-large btn-primary" %>
<% end %>
<p>New user? <%= link_to "Sign up now!", signup_path %></p>
</div>
</div>
The error is resulting from params[:session] being nil which in turn has resulted from your using form_tag instead of form_for in your view, presumably as a result of doing the first exercise at the end of Chapter 9. You can use form_tag, but you have to make the corresponding changes in SessionsController in keeping with RailsCast #270 (i.e. referencing the email address as params[:email] in your find_by_email call.).
I'm working on RoR tutorial, Chapter 8. I am trying to complete section 8.2.4 - Changing the layout links and ran $ bundle exec rspec spec/ and I got the following error:
Failures:
1) Authentication signin with valid information
Failure/Error: click_button "Sign in"
NoMethodError:
undefined method `sign_in' for #<SessionsController:0x007fef66b85fd0>
# ./app/controllers/sessions_controller.rb:9:in `create'
# (eval):2:in `click_button'
# ./spec/requests/authentication_pages_spec.rb:35:in `block (4 levels) in <top (required)>'
2) Authentication signin with valid information
Failure/Error: click_button "Sign in"
NoMethodError:
undefined method `sign_in' for #<SessionsController:0x007fef66b33eb0>
# ./app/controllers/sessions_controller.rb:9:in `create'
# (eval):2:in `click_button'
# ./spec/requests/authentication_pages_spec.rb:35:in `block (4 levels) in <top (required)>'
3) Authentication signin with valid information
Failure/Error: click_button "Sign in"
NoMethodError:
undefined method `sign_in' for #<SessionsController:0x007fef6698bba8>
# ./app/controllers/sessions_controller.rb:9:in `create'
# (eval):2:in `click_button'
# ./spec/requests/authentication_pages_spec.rb:35:in `block (4 levels) in <top (required)>'
4) Authentication signin with valid information
Failure/Error: click_button "Sign in"
NoMethodError:
undefined method `sign_in' for #<SessionsController:0x007fef68286130>
# ./app/controllers/sessions_controller.rb:9:in `create'
# (eval):2:in `click_button'
# ./spec/requests/authentication_pages_spec.rb:35:in `block (4 levels) in <top (required)>'
Finished in 1.34 seconds
44 examples, 4 failures
Failed examples:
rspec ./spec/requests/authentication_pages_spec.rb:39 # Authentication signin with valid information
rspec ./spec/requests/authentication_pages_spec.rb:40 # Authentication signin with valid information
rspec ./spec/requests/authentication_pages_spec.rb:38 # Authentication signin with valid information
rspec ./spec/requests/authentication_pages_spec.rb:41 # Authentication signin with valid information
Based on the output, I checked spec/requests/authentication_pages_spec.rb, but I can't seem to find the error. This is what I have:
require 'spec_helper'
describe "Authentication" do
subject { page }
describe "signin page" do
before { visit signin_path }
it { should have_selector('h1', text: 'Sign in') }
it { should have_selector('title', text: 'Sign in') }
end
describe "signin" do
before { visit signin_path }
describe "with invalid information" do
before { click_button "Sign in" }
it { should have_selector('title', text: 'Sign in') }
it { should have_selector('div.alert.alert-error', text: 'Invalid') }
describe "after visiting antoher page" do
before { click_link "Home" }
it { should_not have_selector('div.alert.alert-error') }
end
end
describe "with valid information" do
let(:user) { FactoryGirl.create(:user) }
before do
fill_in "Email", with: user.email
fill_in "Password", with: user.password
click_button "Sign in"
end
it { should have_selector('title', text: user.name) }
it { should have_link('Profile', href: user_path(user)) }
it { should have_link('Sign out', href: signout_path) }
it { should_not have_link('Sign in', href: signin_path) }
end
end
end
I can't seem to find the error. Any suggestions on where I should look based on the error output? Thank you.
Check your config/routes.rb file to make sure that:
match '/signin', to: 'sessions#new'
matches what your session controllers is seeing. The create method for your "sessions_controller.rb" should have:
def create
user = User.find_by_email(params[:session][:email].downcase)
if user && user.authenticate(params[:session][:password])
sign_in user
redirect_back_or user
else
flash.now[:error] = 'Invalid email/password combination'
render 'new'
end
end
Just my guess. I'm currently around that area too in the tutorial. Best of luck and I hope that helps!
A bit late probably but anyways...
Check if you got "include SessionsHelper" in app/controllers/application_controller.rb
helpers are included into views by default but you have to explicitly include them in controllers
Had three engineers working on trying to solve this and no luck. Working through Ruby on rails tutorial - Michael Hartl, Chapter 8 and can not seem to progress. If you are a jedi engineer please write answers in full due to rookie experience/knowledge. Thanks in advance!
errors
Failures:
1) when email format is invalid should be invalid
Failure/Error: #user.email = invalid_address
NoMethodError:
undefined method `email=' for nil:NilClass
# ./spec/models/user_spec.rb:33:in `block (3 levels) in <top (required)>'
# ./spec/models/user_spec.rb:32:in `each'
# ./spec/models/user_spec.rb:32:in `block (2 levels) in <top (required)>'
2) when email format is valid should be valid
Failure/Error: #user.email = valid_address
NoMethodError:
undefined method `email=' for nil:NilClass
# ./spec/models/user_spec.rb:43:in `block (3 levels) in <top (required)>'
# ./spec/models/user_spec.rb:42:in `each'
# ./spec/models/user_spec.rb:42:in `block (2 levels) in <top (required)>'
3) when email address is already taken
Failure/Error: user_with_same_email = #user.dup
TypeError:
can't dup NilClass
# ./spec/models/user_spec.rb:51:in `dup'
# ./spec/models/user_spec.rb:51:in `block (2 levels) in <top (required)>'
4) when password is not present
Failure/Error: before { #user.password = #user.password_confirmation = " " }
NoMethodError:
undefined method `password_confirmation=' for nil:NilClass
# ./spec/models/user_spec.rb:60:in `block (2 levels) in <top (required)>'
5) when password doesn't match confirmation
Failure/Error: before { #user.password_confirmation = "mismatch" }
NoMethodError:
undefined method `password_confirmation=' for nil:NilClass
# ./spec/models/user_spec.rb:65:in `block (2 levels) in <top (required)>'
6) when password confirmation is nil
Failure/Error: before { #user.password_confirmation = nil }
NoMethodError:
undefined method `password_confirmation=' for nil:NilClass
# ./spec/models/user_spec.rb:70:in `block (2 levels) in <top (required)>'
7) with a password that's too short
Failure/Error: before { #user.password = #user.password_confirmation = "a" * 5 }
NoMethodError:
undefined method `password_confirmation=' for nil:NilClass
# ./spec/models/user_spec.rb:76:in `block (2 levels) in <top (required)>'
8) return value of authenticate method with valid password
Failure/Error: before { #user.save }
NoMethodError:
undefined method `save' for nil:NilClass
# ./spec/models/user_spec.rb:81:in `block (2 levels) in <top (required)>'
9) return value of authenticate method with invalid password
Failure/Error: before { #user.save }
NoMethodError:
undefined method `save' for nil:NilClass
# ./spec/models/user_spec.rb:81:in `block (2 levels) in <top (required)>'
10) return value of authenticate method with invalid password
Failure/Error: before { #user.save }
NoMethodError:
undefined method `save' for nil:NilClass
# ./spec/models/user_spec.rb:81:in `block (2 levels) in <top (required)>'
11) Authentication signin page
Failure/Error: before { visit signin_path }
ActionView::Template::Error:
undefined local variable or method `root_path' for #<#<Class:0x007f841ca913c8>:0x007f8419313cc0>
# ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___3328719763930508541_70102689576460'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___3500649280077332684_70102687772720'
# ./spec/requests/authentication_pages_spec.rb:8:in `block (3 levels) in <top (required)>'
12) Authentication signin page
Failure/Error: before { visit signin_path }
ActionView::Template::Error:
undefined local variable or method `root_path' for #<#<Class:0x007f841ca913c8>:0x007f841bba0030>
# ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___3328719763930508541_70102689576460'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___3500649280077332684_70102687772720'
# ./spec/requests/authentication_pages_spec.rb:8:in `block (3 levels) in <top (required)>'
13) Static pages Home page
Failure/Error: before { visit root_path }
NameError:
undefined local variable or method `root_path' for #<RSpec::Core::ExampleGroup::Nested_11::Nested_1:0x007f8419475898>
# ./spec/requests/static_pages_spec.rb:8:in `block (3 levels) in <top (required)>'
14) Static pages Home page
Failure/Error: before { visit root_path }
NameError:
undefined local variable or method `root_path' for #<RSpec::Core::ExampleGroup::Nested_11::Nested_1:0x007f84195c97f8>
# ./spec/requests/static_pages_spec.rb:8:in `block (3 levels) in <top (required)>'
15) Static pages Home page
Failure/Error: before { visit root_path }
NameError:
undefined local variable or method `root_path' for #<RSpec::Core::ExampleGroup::Nested_11::Nested_1:0x007f84196d96e8>
# ./spec/requests/static_pages_spec.rb:8:in `block (3 levels) in <top (required)>'
16) Static pages Help page
Failure/Error: before { visit help_path }
ActionView::Template::Error:
undefined local variable or method `root_path' for #<#<Class:0x007f841b879528>:0x007f84196268b8>
# ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___3328719763930508541_70102689576460'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___3500649280077332684_70102687772720'
# ./spec/requests/static_pages_spec.rb:16:in `block (3 levels) in <top (required)>'
17) Static pages Help page
Failure/Error: before { visit help_path }
ActionView::Template::Error:
undefined local variable or method `root_path' for #<#<Class:0x007f841b879528>:0x007f841bd4b4e8>
# ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___3328719763930508541_70102689576460'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___3500649280077332684_70102687772720'
# ./spec/requests/static_pages_spec.rb:16:in `block (3 levels) in <top (required)>'
18) Static pages About page
Failure/Error: before { visit about_path }
ActionView::Template::Error:
undefined local variable or method `root_path' for #<#<Class:0x007f841b879528>:0x007f841bbab728>
# ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___3328719763930508541_70102689576460'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___3500649280077332684_70102687772720'
# ./spec/requests/static_pages_spec.rb:23:in `block (3 levels) in <top (required)>'
19) Static pages About page
Failure/Error: before { visit about_path }
ActionView::Template::Error:
undefined local variable or method `root_path' for #<#<Class:0x007f841b879528>:0x007f841a1f8c18>
# ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___3328719763930508541_70102689576460'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___3500649280077332684_70102687772720'
# ./spec/requests/static_pages_spec.rb:23:in `block (3 levels) in <top (required)>'
20) Static pages Contact page
Failure/Error: before { visit contact_path }
ActionView::Template::Error:
undefined local variable or method `root_path' for #<#<Class:0x007f841b879528>:0x007f841b8baf00>
# ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___3328719763930508541_70102689576460'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___3500649280077332684_70102687772720'
# ./spec/requests/static_pages_spec.rb:30:in `block (3 levels) in <top (required)>'
21) Static pages Contact page
Failure/Error: before { visit contact_path }
ActionView::Template::Error:
undefined local variable or method `root_path' for #<#<Class:0x007f841b879528>:0x007f841be450b0>
# ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___3328719763930508541_70102689576460'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___3500649280077332684_70102687772720'
# ./spec/requests/static_pages_spec.rb:30:in `block (3 levels) in <top (required)>'
22) User pages profile page
Failure/Error: before { visit user_path(user) }
ActionView::Template::Error:
undefined local variable or method `root_path' for #<#<Class:0x007f841bed35e0>:0x007f841bedc2d0>
# ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___3328719763930508541_70102689576460'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___3500649280077332684_70102687772720'
# ./spec/requests/user_pages_spec.rb:9:in `block (3 levels) in <top (required)>'
23) User pages profile page
Failure/Error: before { visit user_path(user) }
ActionView::Template::Error:
undefined local variable or method `root_path' for #<#<Class:0x007f841bed35e0>:0x007f841b8890e0>
# ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___3328719763930508541_70102689576460'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___3500649280077332684_70102687772720'
# ./spec/requests/user_pages_spec.rb:9:in `block (3 levels) in <top (required)>'
24) User pages signup with invalid information should not create a user
Failure/Error: before { visit signup_path }
ActionView::Template::Error:
undefined local variable or method `root_path' for #<#<Class:0x007f841bed35e0>:0x007f841bfd8940>
# ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___3328719763930508541_70102689576460'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___3500649280077332684_70102687772720'
# ./spec/requests/user_pages_spec.rb:17:in `block (3 levels) in <top (required)>'
25) User pages signup with valid information should create a user
Failure/Error: before { visit signup_path }
ActionView::Template::Error:
undefined local variable or method `root_path' for #<#<Class:0x007f841bed35e0>:0x007f841bd018c0>
# ./app/views/layouts/_header.html.erb:4:in `_app_views_layouts__header_html_erb___3328719763930508541_70102689576460'
# ./app/views/layouts/application.html.erb:11:in `_app_views_layouts_application_html_erb___3500649280077332684_70102687772720'
# ./spec/requests/user_pages_spec.rb:17:in `block (3 levels) in <top (required)>'
Finished in 0.60263 seconds
33 examples, 25 failures
user_spec.rb
require 'spec_helper'
describe User do
before do
#user = User.new(name: "Example User", email: "user#example.com",
password: "foobar", password_confirmation: "foobar")
end
subject { #user }
it { should respond_to(:name) }
it { should respond_to(:email) }
it { should respond_to(:password_digest) }
it { should respond_to(:password) }
it { should respond_to(:password_confirmation) }
it { should respond_to(:authenticate) }
it { should be_valid }
describe "when name is too long" do
before { #user.name = "a" * 51 }
it { should_not be_valid }
end
end
describe "when email format is invalid" do
it "should be invalid" do
addresses = %w[user#foo,com user_at_foo.org example.user#foo.
foo#bar_baz.com foo#bar+baz.com]
addresses.each do |invalid_address|
#user.email = invalid_address
#user.should_not be_valid
end
end
end
describe "when email format is valid" do
it "should be valid" do
addresses = %w[user#foo.COM A_US-ER#f.b.org frst.lst#foo.jp a+b#baz.cn]
addresses.each do |valid_address|
#user.email = valid_address
#user.should be_valid
end
end
end
describe "when email address is already taken" do
before do
user_with_same_email = #user.dup
user_with_same_email.email = #user.email.upcase
user_with_same_email.save
end
it { should_not be_valid }
end
describe "when password is not present" do
before { #user.password = #user.password_confirmation = " " }
it { should_not be_valid }
end
describe "when password doesn't match confirmation" do
before { #user.password_confirmation = "mismatch" }
it { should_not be_valid }
end
describe "when password confirmation is nil" do
before { #user.password_confirmation = nil }
it { should_not be_valid }
end
describe "with a password that's too short" do
before { #user.password = #user.password_confirmation = "a" * 5 }
it { should be_invalid }
end
describe "return value of authenticate method" do
before { #user.save }
let(:found_user) { User.find_by_email(#user.email) }
describe "with valid password" do
it { should == found_user.authenticate(#user.password) }
end
describe "with invalid password" do
let(:user_for_invalid_password) { found_user.authenticate("invalid") }
it { should_not == user_for_invalid_password }
specify { user_for_invalid_password.should be_false }
end
end
authentication_pages_spec
require 'spec_helper'
describe "Authentication" do
subject { page }
describe "signin page" do
before { visit signin_path }
it { should have_selector('h1', text: 'Sign in') }
it { should have_selector('title', text: 'Sign in') }
end
end
static_pages_spec
require 'spec_helper'
describe "Static pages" do
subject { page }
describe "Home page" do
before { visit root_path }
it { should have_selector('h1', text: 'Sample App') }
it { should have_selector('title', text: full_title('')) }
it { should_not have_selector 'title', text: '| Home' }
end
describe "Help page" do
before { visit help_path }
it { should have_selector('h1', text: 'Help') }
it { should have_selector('title', text: full_title('Help')) }
end
describe "About page" do
before { visit about_path }
it { should have_selector('h1', text: 'About') }
it { should have_selector('title', text: full_title('About Us')) }
end
describe "Contact page" do
before { visit contact_path }
it { should have_selector('h1', text: 'Contact') }
it { should have_selector('title', text: full_title('Contact')) }
end
end
user_pages_spec
require 'spec_helper'
describe "User pages" do
subject { page }
describe "profile page" do
let(:user) { FactoryGirl.create(:user) }
before { visit user_path(user) }
it { should have_selector('h1', text: user.name) }
it { should have_selector('title', text: user.name) }
end
describe "signup" do
before { visit signup_path }
let(:submit) { "Create my account" }
describe "with invalid information" do
it "should not create a user" do
expect { click_button submit }.not_to change(User, :count)
end
end
describe "with valid information" do
before do
fill_in "Name", with: "Example User"
fill_in "Email", with: "user#example.com"
fill_in "Password", with: "foobar"
fill_in "Confirmation", with: "foobar"
end
it "should create a user" do
expect { click_button submit }.to change(User, :count).by(1)
end
end
end
end
gemfile
source 'https://rubygems.org'
gem 'rails', '3.2.6'
gem 'bootstrap-sass', '2.0.0'
gem 'bcrypt-ruby', '3.0.1'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
group :development, :test do
gem 'sqlite3', '1.3.5'
gem 'rspec-rails', '2.10.0'
end
gem 'annotate', '~> 2.4.1.beta', group: :development
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '3.2.4'
gem 'coffee-rails', '3.2.2'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '1.2.3'
end
gem 'jquery-rails', '2.0.0'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# To use Jbuilder templates for JSON
# gem 'jbuilder'
group :test do
gem 'capybara', '1.1.2'
gem 'factory_girl_rails', '1.4.0'
end
group :production do
gem 'pg', '0.12.2'
end
# Use unicorn as the app server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'debugger'
Thanks in advance guys :)
It looks like you forgot to prepare the test database. Run this on the command line:
rake db:test:prepare
I would definitely recommend that you read A Guide to Testing Rails Applications (3.1 Preparing your Application for Testing) to get a sense of what needs to happen before you run your tests.