我目前在本教程的清单10.32和10.33之间:http://ruby.railstutorial.org/chapters/user-microposts#sec-manipulating_microposts
我在运行测试时遇到了问题。输出如下:
Failures:
1) Micropost pages micropost creation with invalid information should not create a micropost
Failure/Error: expect { click_button "Post" }.not_to change(Micropost, :count)
ActionController::ParameterMissing:
param not found: micropost
# ./app/controllers/microposts_controller.rb:23:in `micropost_params'
# ./app/controllers/microposts_controller.rb:8:in `create'
# ./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)>'
2) Micropost pages micropost creation with invalid information error messages
Failure/Error: before { click_button "Post" }
ActionController::ParameterMissing:
param not found: micropost
# ./app/controllers/microposts_controller.rb:23:in `micropost_params'
# ./app/controllers/microposts_controller.rb:8:in `create'
# ./spec/requests/micropost_pages_spec.rb:20:in `block (5 levels) in <top (required)>'
3) Micropost pages micropost creation with valid information should create a micropost
Failure/Error: before { fill_in 'micropost_content', with: "Lorem ipsum" }
Capybara::ElementNotFound:
Unable to find field "micropost_content"
# ./spec/requests/micropost_pages_spec.rb:27:in `block (4 levels) in <top (required)>'
Finished in 0.56491 seconds
3 examples, 3 failures
Failed examples:
rspec ./spec/requests/micropost_pages_spec.rb:15 # Micropost pages micropost creation with invalid information should not create a micropost
rspec ./spec/requests/micropost_pages_spec.rb:21 # Micropost pages micropost creation with invalid information error messages
rspec ./spec/requests/micropost_pages_spec.rb:28 # Micropost pages micropost creation with valid information should create a micropost
这是目前失败的测试:
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
这意味着@micropost变量显然没有设置,但它是在静态页面控制器中设置的。我已经检查了一段时间,现在确实发现了与教程的差异,但没有成功找到任何。
git存储库位于:https://github.com/afuhrtrumpet/sample_app/tree/user-microposts
有没有人看到这个问题?
答案 0 :(得分:0)
问题是这里缺少'='标志:
<%= f.text_area :content, placeholder: "Compose new micropost..." %>