rspec不报告错误行数
对于我的几乎所有规格,当rspec报告错误时,它会告诉我路径末尾的行号,例如
rspec ./spec/controllers/eclubs_controller_spec.rb:21
但是在我的一个规范中,它会报告错误位置
rspec ./spec/controllers/eclubs/members_controller_spec.rb[1:1:2:3:1]
在块的嵌套方面可能有意义,但坦率地说是相当神秘的。
有效的规范的顶部看起来像这样
require 'rails_helper' describe EclubsController do
并且不起作用的那个看起来像这样
require 'rails_helper' describe Eclubs::MembersController do
我在两个文件中看到的唯一区别是一个控制器是命名空间,但我有其他命名空间控制器正确报告错误行。
是什么造成的?
当行号不够独特以识别相关示例时,RSpec使用示例id。
在动态定义示例时,例如在循环中,可能会发生这种情况:
(0..10).each do |i| it do expect(i).to_not eq(5) end end # rspec './my_spec.rb[1:6]'
或者在使用共享示例组时:
RSpec.shared_examples_for "not equal 5" do |i| it do expect(i).to_not eq(5) end end RSpec.describe do it_behaves_like "not equal 5", 5 it_behaves_like "not equal 5", 4 end # rspec './my_spec.rb[2:1:1]'
- 黄瓜和自定义RSpec匹配器
- RSpec 1.3.3 Rails 2.3.9 Webrat 0.7.3“未定义方法`assign`”
- RailsTutorial 3.2 Ch 9 – “before {valid_signin(user)}”导致RSpec测试失败
- Capybara-webkit无法处理与bootstrap glyphicon的链接
- 如何在RSpec中测试send_data? 或者……在这种情况下我应该测试什么?
- rspec之前(:每个)使用factorygirl创建模型不工作
- 在Ruby On Rails上学习BDD的途径是什么?
- rail3 / rspec / devise:除非我添加一个dummy = subject.current_user.inspect,否则rspec控制器测试失败
- RSpec错误“未初始化的常量FactoryGirl(名称错误)”