我遇到了rspec的一些問題,它會返回一個錯誤,即使所有東西都在localhost上工作。未定義的方法`node_name'爲零:NilClass
1) Item pages item creation with invalid information should not create an item
Failure/Error: expect { click_button "Add" }.not_to change(Item, :count)
NoMethodError:
undefined method `node_name' for nil:NilClass
# (eval):2:in `click_button'
# ./spec/requests/item_pages_spec.rb:20:in `block (5 levels) in <top (required)>'
# ./spec/requests/item_pages_spec.rb:20:in `block (4 levels) in <top (required)>'
item_pages_spec.rb
require 'spec_helper'
describe "Item pages" do
subject { page }
let(:user) { FactoryGirl.create(:user) }
let(:list) { FactoryGirl.create(:list, user: user)}
before { sign_in user }
describe "item creation" do
before do
visit user_list_path(user, list)
click_link "Add wish"
end
describe "with invalid information" do
it "should not create an item" do
expect { click_button "Add" }.not_to change(Item, :count)
end
# describe "error messages" do
# before { click_button "Add" }
# it { should have_content('error') }
# end
end
describe "with valid information" do
before { fill_in 'item_title', with: "Lorem ipsum" }
it "should create a item" do
expect { click_button "Add" }.to change(Item, :count).by(1)
end
end
end
end
形式創建一個項目
<% if signed_in? %>
<div id="addWish" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="addWishLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="addWishLabel">Add wish</h3>
</div>
<div class="modal-body">
<%= form_for(@item) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<div class="field">
<%= f.hidden_field :list_id, value: @list.id %>
<%= f.text_field :title, placeholder: "Title..." %>
<%= f.text_field :link, placeholder: "Link..." %>
</div>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<%= f.submit "Add", class: "btn btn-primary" %>
<% end %>
</div>
</div>
<% end %>
我很新的軌道和任何幫助因而非常感謝!
你是什麼意思,即使「一切工作在本地主機」。 你是否試圖在不同的主機上運行不同的Capybara驅動程序測試? –
不好意思,因爲缺乏清晰度。我的意思是,當我通過瀏覽器測試時,一切正常。 –