代码之家  ›  专栏  ›  技术社区  ›  Finglas

RSpec-通用故障消息,而不是有用的输出

  •  2
  • Finglas  · 技术社区  · 14 年前

    这是使用RSpec2-无论发生什么,当期望值不匹配时,我似乎得到以下错误。我确信(虽然我暂时无法尝试)在版本1中,下面的代码将声明没有调用方法“methods”。

    describe "Test" do
      it "should do" do
        my_mock = mock("my mock")
        my_mock.should_receive(:methods)
        obj = Shaun.new(my_mock)
      end
    end
    
    class Shaun
      def initialize(mock)
        #mock.methods
      end
    end
    

    错误

    Failures:
      1) Test should do
    C:/Program Files/Ruby/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.0/lib/rspec/core/formatters/base_formatter.rb:138:in `block in find_failed_line':
     undefined method `downcase' for nil:NilClass (NoMethodError)
            from C:/Program Files/Ruby/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.0/lib/rspec/core/formatters/base_formatter.rb:136:in `each'
            from C:/Program Files/Ruby/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.0/lib/rspec/core/formatters/base_formatter.rb:136:in `detect'
            from C:/Program Files/Ruby/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.0/lib/rspec/core/formatters/base_formatter.rb:136:in `find_failed_li
    ne'
            from C:/Program Files/Ruby/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.0/lib/rspec/core/formatters/base_formatter.rb:122:in `read_failed_li
    ne'
            from C:/Program Files/Ruby/Ruby192/lib/ruby/gems/1.9.1/gems/rspec-core-2.0.0/lib/rspec/core/formatters/base_text_formatter.rb:27:in `block in d
    ump_failures'
    
    
    1 回复  |  直到 14 年前
        1
  •  1
  •   Bitterzoet    14 年前

    在这里工作得很好,rspec 2.0.1和REE 1.8.7。将需要再次检查1.9.2,因为我还没有在这个系统上。

    发表评论时:

    Failures:
    1) Test should do
       Failure/Error: my_mock.should_receive(:methods)
       (Mock "my mock").methods(any args)
           expected: 1 time
           received: 0 times
       # ./test_rspec.rb:4