关注ruby.railstutorial.org/并获得失败的测试

时间:2011-03-14 07:08:10

标签: ruby-on-rails ruby-on-rails-3 testing integration-testing

我正在使用Ruby 1.9.2和Rails 3.0.3

我一直在本教程中遇到失败的测试错误,例如:

1) UsersController GET 'show' should show the user's micropost
 Failure/Error: get :show, :id => @user
 undefined method `model_name' for NilClass:Class
 # ./app/views/users/show.html.erb:10:in `_app_views_users_show_html_erb__2659465448390875355_2173812560_4463455946834160058'
 # ./spec/controllers/users_controller_spec.rb:39:in `block (3 levels) in <top (required)>'

show.html.erb:10是:

<% unless @user.microposts.empty? %>
    <table class="microposts" summary="User microposts">
        <%= render @microposts %>   #line 10
    </table>
  <%= will_pagination @microposts %>
<% end %>

users_controller_spec.rb:39是:

describe "GET 'show'" do
before(:each) do
@user = Factory(:user)
end
.
.
.
it "should show the user's micropost" do
mp1 = Factory(:micropost, :user => @user, :content => "Foo bar")
mp2 = Factory(:micropost, :user => @user, :content => "Baz quux")
get :show, :id => @user
response.should have_selector("span.content", :content => mp1.cntent)
response.should have_selector("span.content", :content => mp2.content)
end

和我的app / controllers / users_controller.rb在哪里定义微博是:

  def show
     @user = User.find(params[:id])
     @microposts = @user.microposts.paginate(:page => params[:page])
     @title = @user.name
  end

任何帮助将不胜感激。我总共有14个错误。我的其他错误是关于

 Failure/Error: get :edit, :id => @user
 @controller is nil: make sure you set it in your test's setup method.

Failure/Error: test_sign_in(wrong_user)
 undefined method `sign_in' for nil:NilClass

我也在使用Factory作为测试登录。我不确定这是否是一个问题。我提到这个是因为一些错误是:

  9) authentication of edit/update pages GET 'index' for signed-in users should have the right title
 Failure/Error: @user = test_sign_in(Factory(:user))
 Validation failed: Email has already been taken
 # ./spec/controllers/users_controller_spec.rb:222:in `block (4 levels) in <top (required)>'

如果您需要查看更多代码,请告知我们。

如果有人可以指导我到一个地方了解有关调试的更多信息,那么这也将是一个很大的帮助。

1 个答案:

答案 0 :(得分:0)

对于错误1,请尝试检查您的文件名是否有拼写和案例 对于错误9,请尝试仔细检查哪个...将您的代码粘贴到。
可以在https://github.com/railstutorial

找到本教程的工作代码