rspec - Rails tutorial Chapter 9.3 Failing tests -
i looked @ pass questions, couldn't find 1 fix problem. these failed tests. visited users index page via browser , saw sign in title.
failures: 1) authorization non-signed-in users in users controller visiting edit page failure/error: { should have_selector('title', text: 'sign in') } expected css "title" text "sign in" return # ./spec/requests/authentication_pages_spec.rb:75:in `block (5 levels) in <top (required)>' 2) authorization non-signed-in users in users controller visiting user index failure/error: { should have_selector('title', text: 'sign in') } expected css "title" text "sign in" return # ./spec/requests/authentication_pages_spec.rb:85:in `block (5 levels) in <top (required)>' finished in 4.65 seconds 69 examples, 2 failures failed examples: rspec ./spec/requests/authentication_pages_spec.rb:75 # authorization non-signed-in users in users controller visiting edit page rspec ./spec/requests/authentication_pages_spec.rb:85 # authorization non-signed-in users in users controller visiting user index authentication_pages_spec.rb
describe "authorization" describe "for non-signed-in users" let(:user) { factorygirl.create(:user) } describe "when attempting visit protected page" before 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" "should render desired protected page" page.should have_selector('title', text: 'edit user') end end end describe "in users controller" let(:user) { factorygirl.create(:user) } describe "visiting edit page" before { visit edit_user_path(user) } { should have_selector('title', text: 'sign in') } end describe "submitting update action" before { put user_path(user) } specify { response.should redirect_to(signin_path) } end describe "visiting user index" before { visit users_path } { should have_selector('title', text: 'sign in') } end end routes.rb
sampleapp::application.routes.draw resources :users resources :sessions, only: [:new, :create, :destroy] root to: 'static_pages#home' match '/signup', to: 'users#new' match '/signin', to: 'sessions#new' match '/signout', to: 'sessions#destroy', via: :delete match '/help', to: 'static_pages#help' match '/about', to: 'static_pages#about' match '/contact', to: 'static_pages#contact' users_controllers.rb
class userscontroller < applicationcontroller before_filter :signed_in_user, only: [:index, :edit, :update] before_filter :correct_user, only: [:edit, :update] def show @user = user.find(params[:id]) end def new @user = user.new end def index @users = user.all end def edit @user = user.find(params[:id]) end def update @user = user.find(params[:id]) if @user.update_attributes(params[:user]) flash[:success] = "profile updated" sign_in @user redirect_to @user else render 'edit' end end def create @user = user.new(params[:user]) if @user.save sign_in @user flash[:success] = "welcome sample app!" redirect_to @user else render 'new' end end private def correct_user @user = user.find(params[:id]) redirect_to(root_path) unless current_user?(@user) end end thanks in advance
you missing following code in authentication_pages_spec.rb:
describe "authorization" subject { page } # line. describe "for non-signed-in users" let(:user) { factorygirl.create(:user) } . . . refer http://ruby.railstutorial.org/chapters/filling-in-the-layout#sec-pretty_rspec.
alternatively, replace
it { should have_selector('title', text: 'sign in') } with
page.should have_selector('title', text: 'sign in')
Comments
Post a Comment