似たような性質のエラーがいくつか発生していますが、それらを修正する方法がわかりません。私が直面している問題の 1 つは、チュートリアルの新しいバージョンと古いバージョンの違いです (いくつかの違いがあることはわかっています)。
私の仕様は次のとおりです。
ルビーのバージョン: 1.9.2p320
レールのバージョン: 3.2.13
Rスペック: 2.11.1
コンピューター: Macbook Pro OS X Mountain Lion
エラー
5) Micropost pages micropost creation with invalid information should not create a micropost
Failure/Error: expect { click_button "Post" }.not_to change(Micropost, :count)
NameError:
undefined local variable or method `user' for #<MicropostsController:0x007fc7a7c64078>
# ./app/controllers/microposts_controller.rb:5:in `create'
# (eval):2:in `click_button'
# ./spec/requests/micropost_pages_spec.rb:16:in `block (5 levels) in <top (required)>'
# ./spec/requests/micropost_pages_spec.rb:16:in `block (4 levels) in <top (required)>'
6) Micropost pages micropost creation with invalid information error messages
Failure/Error: before { click_button "Post" }
NameError:
undefined local variable or method `user' for #<MicropostsController:0x007fc7a7897e90>
# ./app/controllers/microposts_controller.rb:5:in `create'
# (eval):2:in `click_button'
# ./spec/requests/micropost_pages_spec.rb:20:in `block (5 levels) in <top (required)>'
7) Micropost pages micropost creation with valid information should create a micropost
Failure/Error: expect { click_button "Post" }.to change(Micropost, :count).by(1)
NameError:
undefined local variable or method `user' for #<MicropostsController:0x007fc7a7bdfb98>
# ./app/controllers/microposts_controller.rb:5:in `create'
# (eval):2:in `click_button'
# ./spec/requests/micropost_pages_spec.rb:29:in `block (5 levels) in <top (required)>'
# ./spec/requests/micropost_pages_spec.rb:29:in `block (4 levels) in <top (required)>'
Micropost_controller.rb
class MicropostsController < ApplicationController
before_filter :signed_in_user
def create
@micropost = current user.microposts.build(params[:micropost])
if @micropost.save
flash[:success] = "Micropost created!"
redirect_to root_path
else
render 'static_pages/home'
end
end
def destroy
end
end
micropost_pages_spec.rb
require 'spec_helper'
describe "Micropost pages" do
subject { page }
let(:user) { FactoryGirl.create(:user) }
before { sign_in user }
describe "micropost creation" do
before { visit root_path }
describe "with invalid information" do
it "should not create a micropost" do
expect { click_button "Post" }.not_to change(Micropost, :count)
end
describe "error messages" do
before { click_button "Post" }
it { should have_content('error') }
end
end
describe "with valid information" do
before { fill_in 'micropost_content', with: "Lorem ipsum" }
it "should create a micropost" do
expect { click_button "Post" }.to change(Micropost, :count).by(1)
end
end
end
end