初めての視聴テストです。モック/スタブ/ダブルの概念全体を理解しているかどうかわからないので、おそらく問題があります。
シンプルなログイン/サインアップをテストしています | ユーザー名/ログアウト リンク。
application.html.erb:
...
<ul>
<% if user_signed_in? %>
<li>
<%= link_to('Logout', destroy_user_session_path, :method => :delete) %>
<%= current_user.username %>
</li>
<% else %>
<li>
<%= link_to('Login', new_user_session_path) %>
<%= link_to('Sign up', new_user_registration_path) %>
</li>
</ul>
<% end %>
...
application.hmtl.erb_spec.rb:
require 'spec_helper'
describe "layouts/application.html.erb" do
context "when user is signed in" do
before :each do
view.stub(:user_signed_in?) { true }
current_user = double()
current_user.stub(:username) { "Joe" }
render
end
it "displays logout link" do
expect(rendered).to have_link 'Logout'
end
it "displays username" do
expect(rendered).to have_content 'Joe'
end
...
end
end
エラーが発生します:
Failure/Error: render
ActionView::Template::Error:
undefined method 'authenticate' for nil:NilClass
に沿って<%= current_user.username %>
このユーザー名スタブが機能していないようですが、何が問題なのですか?