Ok so I'm kinda new, but have somewhat of an idea of what I'm doing, but this one just has me stumped for the past couple hours, so any help is very much appreciated. I'm building a site and have been using Rspec and Capybara to test my site as I'm moving along. I ended up needing to remove turbolinks to improve functionality for my jscripts. The next time I try to run tests, literally 50% of my test suite just magically broke. I've narrowed it down to that the commonality between all the failures was that the "visit" either appeared in or just before the code block. So basically removing Turbolinks somehow blew Capybara up or Rspec. I'm really having some trouble figuring this one out. I tried updating the gems, that didn't work. I guess the next step is either skip the TDD concept, which I don't want to do, or start uninstalling the gems and do a reinstall and pray that that doesn't render my app useless... Any help anyone can provide is much appreciated, and if you're in NYC I'll buy you a beer.
There are also other tests that are failing that don't require any sort of authentication, just to check the page for title and content and those are failing to. I bring that up only to say I don't think that FactoryGirl is causing the problem.
Cheers.
The errors
2) User pages profile page
Failure/Error: before { visit user_path(user) }
NoMethodError:
undefined method `user_path' for #<RSpec::ExampleGroups::UserPages::ProfilePage:0x00000004290410>
# ./spec/requests/user_pages_spec.rb:10:in `block (3 levels) in <top (required)>'
3) User pages profile page
Failure/Error: before { visit user_path(user) }
NoMethodError:
undefined method `user_path' for #<RSpec::ExampleGroups::UserPages::ProfilePage:0x00000004207c00>
# ./spec/requests/user_pages_spec.rb:10:in `block (3 levels) in <top (required)>'
4) User pages signup page
Failure/Error: before { visit signup_path }
NameError:
undefined local variable or method `signup_path' for #<RSpec::ExampleGroups::UserPages::SignupPage:0x000000041b3088>
# ./spec/requests/user_pages_spec.rb:18:in `block (3 levels) in <top (required)>'
The test suite code
require 'spec_helper'
describe "User pages" do
subject { page }
#Profile tests
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
#Signup page tests
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
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: "foobar00"
fill_in "Confirmation", with: "foobar00"
end
it "should create a user" do
expect { click_button submit }.to change(User, :count).by(1)
end
end
end
end
try to remove your visiting pages from before blocks .
So , you just need :
describe "signup page" do
feature "should have content 'Sign up' "
visit signup_path
it { should have_content('Sign up') }
end
feature "should have full title 'Sign up' "
visit signup_path
it { should have_title(full_title('Sign up')) }
end
end
And you need to do like this in every describe block .
Ok so to anyone else that runs into this issue, I did some more digging it's not a so uncommon occurrence for Capybara to get weird at times. But I got the route errors to fix and pass green by adding "config.include Rails.application.routes.url_helpers" to the spec_helper.rb file.
Rspec.configure do |config|
*
*
*
config.include Rails.application.routes.url_helpers
end
Unfortunately I can't provide any insight why that line needed to be added, when previously it was not needed. I'll have to leave that answer to someone with more knowledge than myself.
Related
I'm currently working through chapter seven of Rails Tutorial and seem to be stuck at figure 7.22. In brief, I'm unable to get the tests to pass. When I run . . .
bundle exec rspec spec/requests/user_pages_spec.rb
. . . I see a bunch of failed tests that read:
Failures:
1) User pages signup page
Failure/Error: before { visit signup_path }
NameError:
undefined local variable or method `signup_path' for # <RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x007fb2be028410>
# ./user_pages_spec.rb:9:in `block (3 levels) in <top (required)>'
2) User pages signup page
Failure/Error: before { visit signup_path }
NameError:
undefined local variable or method `signup_path' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x007fb2be048ad0>
# ./user_pages_spec.rb:9:in `block (3 levels) in <top (required)>'
3) User pages signup page with invalid information should not create a user
Failure/Error: before { visit signup_path }
NameError:
undefined local variable or method `signup_path' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1::Nested_1:0x007fb2be062e80>
# ./user_pages_spec.rb:9:in `block (3 levels) in <top (required)>'
4) User pages signup page with valid information should create a user
Failure/Error: before { visit signup_path }
NameError:
undefined local variable or method `signup_path' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1::Nested_2:0x007fb2be083158>
# ./user_pages_spec.rb:9:in `block (3 levels) in <top (required)>'
Finished in 0.00374 seconds
4 examples, 4 failures
Failed examples:
rspec ./user_pages_spec.rb:11 # User pages signup page
rspec ./user_pages_spec.rb:12 # User pages signup page
rspec ./user_pages_spec.rb:18 # User pages signup page with invalid information should not create a user
rspec ./user_pages_spec.rb:32 # User pages signup page with valid information should create a user
Randomized with seed 10291
I'm guessing the main error involves the undefined method or varialble "signup_path," but I have no clue whatsoever where it's supposed to be defined or whether it should have at some point automatically been defined by Rails in the first place.
Could someone help me with this?
UPDATE: Below is my routes file.
Thanks for your reply. Here's my routes file. Unless I'm missing something, everything seems OK to me:
SecondSampleApp::Application.routes.draw do
get "users/new"
get "static_pages/home"
get "static_pages/help"
get "static_pages/about"
resources :users
root "static_pages#home"
match "/signup", to: "users#new", via: "get"
match "/help", to: "static_pages#help", via: "get"
match "/about", to: "static_pages#about", via: "get"
match "/contact", to: "static_pages#contact", via: "get"
end
spec/spec_helper.rb
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
RSpec.configure do |config|
config.include Capybara::DSL
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures = true
config.infer_base_class_for_anonymous_controllers = false
config.order = "random"
config.include Rails.application.routes.url_helpers
end
Here are the failing tests in user_pages_spec.rb:
require 'spec_helper'
describe "User pages" do
subject { page }
describe "signup page" do
before { visit signup_path }
it { should have_content('Sign up') }
it { should have_title(full_title('Sign up')) }
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
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
end
When going through the Hartl tutorial and you encounter an undefined local variable or method error or otherwise want to find out what the current definition of a variable or method is supposed to be at that point in the tutorial, the following technique is helpful:
Go to the book on the web
Click the "view as single page" link in the upper right hand corner
With the browser's search command, search backwards from where you are in the tutorial for variable/method name in question. (Note: If there are lots of them, and you're sure it's a method, you can narrow the search to "def variable_or_method_in_question")
Note the definition and the file in which the definition occurs (typically given in the header of the table/listing/figure)
Going to the github repository is helpful sometimes as well, but that shows the final state/location of the code, which can often be misleading.
In your case, this technique results in finding an entry in Table 5.1 which indicates that this variable is a path generated by Rails as a result of the contents of your routes.rb file. You should check the contents of that file and look at the currently defined routes using rake routes on the command line.
This nolonger applies to the tutorial by Michael Hartl http://www.railstutorial.org/book
Spork is not being used in tutorial for Rails 4 now, this may change, I followed the page linked below but it will overwrite the existing spec setup and install Gems not required by the tutorial.
Are you using Spork? If so you have to restart it any time you make changes in routes.rb.
Described in Listing 3.38:
One word of advice when using Spork: after changing a file included in the prefork loading (such as routes.rb), you will have to restart the Spork server to load the new Rails environment. If your tests are failing when you think they should be passing, quit the Spork server with Ctrl-C and restart it.
http://ruby.railstutorial.org/chapters/static-pages#sec-spork
For Rails 5 add code to rails_helper.rb :
include Rails.application.routes.url_helpers
I have been working on the ruby on rails tutorial. I am totally new to this stuff. I am in chapter 9 and totally stuck. I am hoping someone might help me decipher the error messages. Up until now I have just searched them and figured it out but I think it would be more valuable to just learn how to decipher the error message to fix the problem. If it is too long or cumbersome to explain than than I totally understand if no one wants to take it on. I was unable to find something online that helped me with this on my own.
Here are the errors that I am currently getting
1) AuthenticationPages signin with valid information 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"
Capybara::ElementNotFound:
Unable to find button "Sign in"
# ./spec/requests/authentication_pages_spec.rb:61:in `block (7 levels) in <top (required)>'
2) AuthenticationPages signin with valid information authorization for non-signed-in users in the Users controller visiting the edit page
Failure/Error: it { should have_title('Sign in') }
expected #has_title?("Sign in") to return true, got false
# ./spec/requests/authentication_pages_spec.rb:76:in `block (8 levels) in <top (required)>'
3) AuthenticationPages signin with valid information authorization for non-signed-in users in the Users controller as wrong user visiting Users#edit page
Failure/Error: before { sign_in user, no_capybara: true }
NoMethodError:
undefined method `sign_in' for #<RSpec::Core::ExampleGroup::Nested_2::Nested_2::Nested_2::Nested_2::Nested_1::Nested_2::Nested_3::Nested_1:0xabbb9e4>
# ./spec/requests/authentication_pages_spec.rb:87:in `block (8 levels) in <top (required)>'
4) AuthenticationPages signin with valid information authorization for non-signed-in users in the Users controller as wrong user submitting a PATCH request to the User#update action
Failure/Error: before { sign_in user, no_capybara: true }
NoMethodError:
undefined method `sign_in' for #<RSpec::Core::ExampleGroup::Nested_2::Nested_2::Nested_2::Nested_2::Nested_1::Nested_2::Nested_3::Nested_2:0xa82d354>
# ./spec/requests/authentication_pages_spec.rb:87:in `block (8 levels) in <top (required)>'
Finished in 6.6 seconds
65 examples, 4 failures
Failed examples:
rspec ./spec/requests/authentication_pages_spec.rb:66 #
AuthenticationPages signin with valid information authorization for
non-signed-in users when attempting to visit a protected page after
signing in should render the desired protected page
rspec ./spec/requests/authentication_pages_spec.rb:76 #
AuthenticationPages signin with valid information authorization for
non-signed-in users in the Users controller visiting the edit page
rspec ./spec/requests/authentication_pages_spec.rb:91 #
AuthenticationPages signin with valid information authorization for
non-signed-in users in the Users controller as wrong user visiting
Users#edit page
rspec ./spec/requests/authentication_pages_spec.rb:96 #
AuthenticationPages signin with valid information authorization for
non-signed-in users in the Users controller as wrong user submitting a
PATCH request to the User#update action
authentication_pages_spec.rb
require 'spec_helper'
describe "AuthenticationPages" do
subject { page }
describe "signin page" do
before { visit signin_path }
it { should have_content('Sign in') }
it { should have_title('Sign in') }
end
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', text: 'Invalid') }
describe "after visiting another page" do
before { click_link "Home" }
it { should_not have_selector('div.alert.alert-error', text: 'Invalid') }
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('Settings', href: edit_user_path(user)) }
it { should have_link('Sign out', href: signout_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
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
expect(page).to have_title('Edit user')
end
end
end
describe "in the Users controller" do
describe "visiting the edit page" do
before { visit edit_user_path(user) }
it { should have_title('Sign in') }
end
describe "submitting to the update action" do
before { patch user_path(user) }
specify { expect(response).to redirect_to(signin_path) }
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, no_capybara: true }
describe "visiting Users#edit page" do
before { visit edit_user_path(wrong_user) }
it { should_not have_title(full_title('Edit user')) }
end
describe "submitting a PATCH request to the User#update action" do
before { patch user_path(wrong_user) }
specify { expect(response).to redirect_to(root_url) }
end
end
end
end
end
end
end
end
user_pages_spec.rb
require 'spec_helper'
describe "User pages" do
subject { page }
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
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 new 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_title(user.name) }
it { should have_selector('div.alert.alert-success', text: 'Welcome') }
end
it "should create a user" do
expect { click_button submit }.to change(User, :count).by(1)
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_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
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
end
end
end
I am particularly curious what "in 'block(7 levels)in" means. Are the levels something on that page or is it referring to something else? What is 'The block' in reference to?
I also cannot seem to understand the capybara error that I am getting. It appeared in chapter 8, went away and now has come back. The button is there on the page when I bring it up so capybara is just not finding it I guess. Can anyone explain how that works?
What does the 'nested" refer to?
Anyone know a good website that breaks this down? I would be more than happy to do the work myself but I could not find one. I would really love to be able to decipher this myself instead of just googling it and hoping the answer is somewhere or having to rely on someone else to explain it all the time.
Thanks so much for your time and any help.
Now is the time on Stack Overflow when I oversimplify. (Google 'ruby block' to read a lot more on this.) A block in Ruby is a bunch of code that gets passed to a method like an argument. For example,
[1,2,3].each{|n| puts n * n }
each is the method (called on the array [1,2,3]), and everything in the brackets is the block. The way the method each works is, it takes every element in the enumerable it`s called on ([1,2,3]) and yields one element at a time to the code block:
|the first element is 1| puts 1 * 1
|next is 2| puts 2 * 2
|etc| puts 3 * 3
A block can also be written between do...end. The Ruby way is to use brackets if you can fit the block on one line, and do...end otherwise - which is just how you have it in your specs. Everywhere you have a do and a matching end in your specs is a block, nested one inside another. The methods are harder to notice, because RSpec makes it look like natural language, but every time you write describe or it at the start of a line is a method call. (So are let and before and subject and expect, for that matter, which get called with single line blocks in your specs.)
So the message 'block(7 levels)' means your error is nested in that many blocks:
describe "AuthenticationPages" do #starts the first block
...
describe "signup" do #starts the second
and so on.
Now, your error messages. The first and second are basically telling you the same thing - you visit edit_user_path(user) and you don't see a "Sign In" button or "Sign In" in the page title. Check the log/test.log file - what happens when you visit that page? Is it a redirect to the signin page? It ought to be, but it looks like it isn't.
The other two error messages say exactly the same thing - the spec doesn't know what sign_in means. You need to have a method by that name defined somewhere RSpec can find it - either in the spec itself, or the spec_helper file that you require at the top of the spec, or in some file which is itself required inside spec_helper.
Finally, I think Hartl is right - you Google as best you can with error messages and stack traces, ask when you can't find what you're looking for, and you'll get better figuring things out yourself with time.
Re: sign_in -- The sign_in function was added to spec/support/utilities.rb in section 9.1.1, Listing 9.6 (in Rails 4 version of book).
I got the same error because my function in utilities.rb was "signin" without the underscore. Once I added the underscore (and changed the other reference to the same function to match), the test went green.
Still new to Rails, but I have an issue where I am updating two models enabled_reward and child within the enabled_rewards_controller and it is signing out the child who is the current_user.
Can anyone offer some help? I don't know if something is happening to the cookie or the remember_token is being removed in the update_attribute call. I don't have anything involving the child in the view, so I ruled that out.
Thanks in advance
Here is the enabled_rewards_controller update method:
def update
#enabled_reward = EnabledReward.find(params[:id])
if #enabled_reward.update_attributes(params[:enabled_reward])
if #enabled_reward.redeemed
#enabled_reward.child.update_attribute(:points,
#enabled_reward.child.points - #enabled_reward.points)
redirect_to #enabled_reward.child
end
end
end
Here is the rspec test:
before do
sign_in child
visit child_path(child)
end
describe "redeeming reward" do
before { click_button "Redeem" }
it "should still have the child signed in" do
should_not have_link('Sign in') # fails
end
end
Error message:
Failure/Error: should_not have_link('Sign in')
expected link "Sign in" not to return anything
# ./spec/requests/child_pages_spec.rb:284:in `block (4 levels)
in <top (required)>'
Im following [Michael Hartl's tutorial][1] and did the exercises in Chapter 7, and now have 4 errors that I cant figure out how to fix for the life of me. When I test the production app manually, the errors dont exist at all. So I don't know if there is something wrong with my text development or something, but Im at a total loss so I thought I'd post here to see if my total noobness is blinding me...thanks for your help!
Here's the 4 error messages I'm getting:
Failures:
1) signup with invalid information after submission
Failure/Error: it { should have_selector('title', text: "Sign up") }
expected css "title" with text "Sign up" to return something
# ./spec/requests/user_pages_spec.rb:38:in `block (4 levels) in <top (required)>'
2) signup with invalid information after submission
Failure/Error: it { should have_content('error') }
expected there to be content "error" in "after submission"
# ./spec/requests/user_pages_spec.rb:39:in `block (4 levels) in <top (required)>'
3) signup after saving the user
Failure/Error: it { should have_selector('title', text: user.name) }
NoMethodError:
undefined method `name' for nil:NilClass
# ./spec/requests/user_pages_spec.rb:60:in `block (3 levels) in <top (required)>'
4) signup after saving the user
Failure/Error: it { should have_selector('div.alert.alert-success', text: 'Welcome') }
expected css "div.alert.alert-success" with text "Welcome" to return something
# ./spec/requests/user_pages_spec.rb:61:in `block (3 levels) in <top (required)>'
Finished in 6.8 seconds
10 examples, 4 failures
Failed examples:
rspec ./spec/requests/user_pages_spec.rb:38 # signup with invalid information after submission
rspec ./spec/requests/user_pages_spec.rb:39 # signup with invalid information after submission
rspec ./spec/requests/user_pages_spec.rb:60 # signup after saving the user
rspec ./spec/requests/user_pages_spec.rb:61 # signup after saving the user
Here's the code on my user_pages_spec.rb:
require 'spec_helper'
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) }
before { visit user_path(user) }
it { should have_selector('h1', text: user.name) }
it { should have_selector('title', text: user.name) }
end
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_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
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
end
[1]: http://ruby.railstutorial.org/
Here's the template code for views/users/show.html.erb
<% provide(:title, #user.name) %>
<div class="row">
<aside class="span4">
<section>
<h1>
<%= gravatar_for #user %>
<%= #user.name %>
</h1>
</section>
</aside>
</div>
and then here's the users_controller.rb
class UsersController < ApplicationController
def show
#user = User.find(params[:id])
end
def new
#user = User.new
end
def create
#user = User.new(params[:user])
if #user.save
sign_in #user
flash[:success] = "Welcome to the Sample App!"
redirect_to #user
else
render 'new'
end
end
end
Allright y'all,
I dont know if not answering my question was some sort of torturous initiation for noobs in this forum, but after almost 24 hours and a good night sleep, I solved the problem!
After a few G searches, I found that I could be stopping some of the variables from passing through by having "end" in the wrong places. It turns out there were 2 main areas where I was doing this. Once I found and fixed those, all the errors went away.
I will now pat myself on the back. I hope this helps any total noobs who run into this same problem in the future.
I am a newbie working through Hartl. Got to the end of Chapter 8 and when I check my browser for the sign in/sign out every things seems AOK. However when I run this test:
$ bundle exec spec spec/
returns
sis-macbook-pro:sample_app Lagaspi$ bundle exec rspec spec/
..............................F
Failures:
1) User pages signup with valid information after saving the user
Failure/Error: it { should have_link('Sign out') }
expected link "Sign out" to return something
# ./spec/requests/user_pages_spec.rb:48:in `block (5 levels) in <top (required)>'
Finished in 0.60715 seconds
31 examples, 1 failure
Failed examples:
rspec ./spec/requests/user_pages_spec.rb:48 # User pages signup with valid information after saving the user
I have an idea but i'm not exactly sure. So here's my user_pages_spec.rb file:
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) }
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
describe "after saving the user" do
before { click_button submit }
it { should have_link('Sign out') }
end
end
end
end
Go to http://ruby.railstutorial.org/chapters/sign-up?version=3.2#code-after_save_tests, and add those lines into you spec.
could you post your view file? Without it, it's difficult to tell what's wrong. From what I'm seeing, it only says you don't have the link.