19366

Ruby on Rails Tutorial by Michael Hartl. Failing Test in Chapter 9.1

Question:

Hi i'm working through the Hartl's Ruby on Rails Tutorial and i'm stuck with one failing test in Chapter 9.1 of. When I run spec in terminal it returns:

sis-macbook-pro:sample_app Lagaspi$ bundle exec rspec spec/ ...............................F................................ Failures: 1) AuthenticationPages signin with valid information Failure/Error: it { should have_link('Users', href: users_path) } expected link "Users" to return something # ./spec/requests/authentication_pages_spec.rb:37:in `block (4 levels) in <top (required)>' Finished in 1.42 seconds 64 examples, 1 failure Failed examples: rspec ./spec/requests/authentication_pages_spec.rb:37 # AuthenticationPages signin with valid information

Here's my code - authentication_pages_spec.rb

require 'spec_helper' describe "AuthenticationPages" 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 { 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 end

And I think this is the problem line (37):

it { should have_link('Users', href: users_path) }

But what should I do? I'm a newbie and can't figure it out. Thanks Si.

Answer1:

If you're following the tutorial, the link should only be visible if a user is logged in. You haven't eluded to any of the other tests failing when the user is logged in, ie

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)) }

And so with that in mind I'm inclined to think that the issue is in the view, not the spec. At a glance, the spec looks fine.

Does your _header.html.erb include this

... <% if signed_in? %> <li><%= link_to "Users", users_path %></li> ...

Recommend

  • R Leaflet Legend: specify order instead of alphabetical
  • Generating random numbers directly inside a .htaccess file
  • Group variable in cobol
  • Rails 3.2 from SQLite locally to Postgres on Heroku
  • python - calculate orthographic similarity between words of a list
  • Oracle ListaGG, Top 3 most frequent values, given in one column, grouped by ID
  • rapply over a nested list in R
  • Responsive left sidebar open close
  • Prevent page break in text block with iText, XMLWorker
  • File extension of zlib zipped html page?
  • Translating C# to PowerShell in InterIMAP
  • C++ friend class std::vector
  • import scipy.sparse failed
  • SyntaxError: (irb):26: both block arg and actual block given
  • aapt.exe'' finished with non-zero exit value 1
  • How to specify input and output paths from cmd.exe for a PowerShell script?
  • Unexpected token ILLEGAL while running node.js mocha test
  • cygwin cannot exec 'git-add--interactive' permission denied
  • MS Access - How to change the linked table path by amend the table
  • Ajax calls do not work in IE unless you fiddle with security settings
  • Alternative to overridePendingTransition() - Android
  • Webgrid not refreshing after delete MVC
  • Rails Find when some params will be blank
  • MongoError: Incorrect arguments
  • Could not find rake using whenever rails
  • Jquery UI tool tip close icon
  • C++ Partial template specialization - design simplification
  • How to make a tree having multiple type of nodes and each node can have multiple child nodes in java
  • Cassandra Data Model
  • How to make Safari send if-modified-since header?
  • Web-crawler for facebook in python
  • Traverse Array and Display in markup
  • InvalidAuthenticityToken between subdomains when logging in with Rails app
  • Codeigniter doesn't let me update entry, because some fields must be unique
  • Qt: Run a script BEFORE make
  • Django query for large number of relationships
  • How to get NHibernate ISession to cache entity not retrieved by primary key
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • How can I use `wmic` in a Windows PE script?
  • How to push additional view controllers onto NavigationController but keep the TabBar?