对不起,但这开始感觉就像在踢脑袋一样.我完全被RSpec困惑了.在视频之后观看了视频,在教程之后阅读了教程,但我仍然只是停留在正方形.
===这是我正在使用的
http://github.com/fudgestudios/bort/tree/master
===错误
F 1) NoMethodError in 'bidding on an item should work' You have a nil object when you didn't expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.new_record? spec/controllers/auction_controller_spec.rb:16: spec/controllers/auction_controller_spec.rb:6: Finished in 0.067139 seconds 1 example, 1 failure
===这是我的控制器动作
def bid @bid = Bid.new(params[:bid]) @bid.save end
===这是我的考试
require File.dirname(__FILE__) + '/../spec_helper' include ApplicationHelper include UsersHelper include AuthenticatedTestHelper describe "bidding on an item" do controller_name :items before(:each) do @user = mock_user stub!(:current_user).and_return(@user) end it "should work" do post 'bid', :bid => { :auction_id => 1, :user_id => @user.id, :point => 1 } assigns[:bid].should be_new_record end end
=== spec_helper
http://github.com/fudgestudios/bort/tree/master/spec/spec_helper.rb
凌晨3点醒来工作并且当天没有任何成就是非常令人沮丧的.敬请谅解.
你之前有过几件事情(每件事).看到示例是指定帖子应该将计数增加1,您正在处理真实记录,并且根本没有任何理由存根.此外,此时,由于只有一个例子,因此没有理由拥有前一个块.我这样做:
describe ItemsController, "bidding on an item" do fixtures :users it "should create a new Bid" do login_as :quentin lambda do post 'bid', :bid => { :auction_id => 1, :user_id => @user.id, :point => 1 } end.should change(Bid, :count).by(1) end end
我建议的一件事是现在非常精细地创建这些东西,直到你更好地理解它们.从期望开始(帖子应该更改出价计数),运行规范并让失败消息引导您在规范或代码中添加您需要的任何其他内容.