Stefan Hansch
Stefan Hansch

Reputation: 1590

Undefined method `user_path' in test Rspec

I run test rspec and display error:

Failure/Error: before { visit user_path(user) }
   NoMethodError:
     undefined method `user_path' for #<RSpec::ExampleGroups::UserPages::ProfilePage:0xcd1f7c0>

How correct setting route for test?

user_spec.rb:

require 'rails_helper'

describe "User pages" do

  subject { page }

  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
end

My routes.rb, where added i route get '/users/:id', to: 'users#show', :as => :user

Rails.application.routes.draw do

  root 'static_pages#home'
  match '/help', to: 'static_pages#help', via: 'get'
  match '/about', to: 'static_pages#about', via: 'get'
  match '/contact', to: 'static_pages#contact', via: 'get'
  match '/signup', to: 'users#new', via: 'get'

  match '/signin', to: 'sessions#new', via: 'get'
  match '/signout', to: 'sessions#destroy', via: 'delete'
  get '/users/:id', to: 'users#show', :as => :user

  resources :users
  resources :sessions, only: [:new, :create, :destroy]

Explain me, please, how correct add route for test rspec. I use rails 4. M

Upvotes: 2

Views: 1806

Answers (1)

Stefan Hansch
Stefan Hansch

Reputation: 1590

I added type: :feature to describe "profile page" do and issue was fixed. Thank you, BroiSatse!

Upvotes: 2

Related Questions