Ruby on rails 为什么不是';t rspec在模型内部的名称错误应该是什么方面失败?

Ruby on rails 为什么不是';t rspec在模型内部的名称错误应该是什么方面失败?,ruby-on-rails,ruby,ruby-on-rails-3,rspec,Ruby On Rails,Ruby,Ruby On Rails 3,Rspec,我有一个rspec,看起来像: it "should test nil" do u = Upload.new u.save! u.my_method! end class Upload < ActiveRecord::Base def my_method! puts "Made it to my method :)" not_defined_var puts "But didn't get this far :(" end end 该方法如下

我有一个rspec,看起来像:

it "should test nil" do
  u = Upload.new
  u.save!
  u.my_method!
end
class Upload < ActiveRecord::Base
  def my_method!
    puts "Made it to my method :)"
    not_defined_var
    puts "But didn't get this far :("
  end
end
该方法如下所示:

it "should test nil" do
  u = Upload.new
  u.save!
  u.my_method!
end
class Upload < ActiveRecord::Base
  def my_method!
    puts "Made it to my method :)"
    not_defined_var
    puts "But didn't get this far :("
  end
end

我觉得我错过了一些重要的东西。有什么想法吗?

您没有调用方法expect,所以Rspec只是传递。若要比较任何事情是否按预期进行,您必须调用它。要测试代码,必须将响应与预期结果进行比较

例如:

RSpec.describe Account do
  it "has a balance of zero when first created" do
    expect(Account.new.balance).to eq(Money.new(0))
  end
end

您没有调用方法expect,因此Rspec只是传递。若要比较任何事情是否按预期进行,您必须调用它。要测试代码,必须将响应与预期结果进行比较

例如:

RSpec.describe Account do
  it "has a balance of zero when first created" do
    expect(Account.new.balance).to eq(Money.new(0))
  end
end

你有没有可能在某个地方定义了一个
方法,而这个方法正在吞噬它呢?我搜索了upload.rb和upload\u spec.rb,但它们不在那里。可以在任何其他位置设置此选项吗?问题是我可以在我们的生产日志中看到错误——所以我认为它只是在某些规范设置中被忽略了。你有没有可能在某个地方定义了一个
方法,它正在吞噬它?我搜索了我的upload.rb和upload\u spec.rb,但它们不在那里。可以在任何其他位置设置此选项吗?问题是我可以在我们的生产日志中看到错误——所以我认为它只是在一些规范设置中被忽略了。谢谢。我最后使用了“expect{u.my_method!}。要更改{u.updated_at}”,谢谢。我最终使用了“expect{u.my_method!}.to change{u.updated_at}”