Rails 3 + Rspec:Rspec说测试正在等待,但它们应该通过

时间:2014-04-28 21:41:18

标签: ruby-on-rails rspec

我有一个spec文件:

require 'spec_helper'

describe Search do
  it should { respond_to(:theme_ids) }
  it should { respond_to(:imprint_ids) }
  it should { respond_to(:language_ids) }
  it should { respond_to(:award_ids) }
  it should { respond_to(:dra) }
  it should { respond_to(:intervention) }
  it should { respond_to(:guided_reading) }
  it should { respond_to(:lexile) }
  it should { respond_to(:accel_bot) }
  it should { respond_to(:accel_top) }
  it should { respond_to(:interest_low) }
  it should { respond_to(:interest_high) }
end

我在app / models / search.rb

中写的课程
class Search
  attr_reader :theme_ids, :imprint_ids, :language_ids, :award_ids, :dra, :intervention, :guided_reading, :lexile, :accel_bot, :accel_top,
              :interest_low, :interest_high

它适用于控制台:

    1.9.3-p484 :002 > Search.new({h: 1})
     => {}

然而,当我运行我的测试时,它们都悬而未决:

    Nets-Mac-Pro:mysite emai$ be rspec spec/models/search_spec.rb 
    /Users/emai/.rvm/gems/ruby-1.9.3-p484@mysite/gems/ruby-debug-ide-0.4.18/lib/ruby-debug-ide/command.rb:27: warning: already initialized constant DEF_OPTIONS
    ************

    Pending:
      Search #<RSpec::Matchers::BuiltIn::PositiveOperatorMatcher:0x007ff701ec5798>
        # Not yet implemented
        # ./spec/models/search_spec.rb:4
      Search #<RSpec::Matchers::BuiltIn::PositiveOperatorMatcher:0x007ff701ec4ac8>
        # Not yet implemented
        # ./spec/models/search_spec.rb:5
      Search #<RSpec::Matchers::BuiltIn::PositiveOperatorMatcher:0x007ff701ecc728>
        # Not yet implemented
        # ./spec/models/search_spec.rb:6
      Search #<RSpec::Matchers::BuiltIn::PositiveOperatorMatcher:0x007ff701ecb968>
        # Not yet implemented
        # ./spec/models/search_spec.rb:7
      Search #<RSpec::Matchers::BuiltIn::PositiveOperatorMatcher:0x007ff701ecb008>
        # Not yet implemented
        # ./spec/models/search_spec.rb:8
      Search #<RSpec::Matchers::BuiltIn::PositiveOperatorMatcher:0x007ff701eca4c8>
        # Not yet implemented
        # ./spec/models/search_spec.rb:9
      Search #<RSpec::Matchers::BuiltIn::PositiveOperatorMatcher:0x007ff701ec9c30>
        # Not yet implemented
        # ./spec/models/search_spec.rb:10
      Search #<RSpec::Matchers::BuiltIn::PositiveOperatorMatcher:0x007ff701ec9488>
        # Not yet implemented
        # ./spec/models/search_spec.rb:11
      Search #<RSpec::Matchers::BuiltIn::PositiveOperatorMatcher:0x007ff701ed0fd0>
        # Not yet implemented
        # ./spec/models/search_spec.rb:12
      Search #<RSpec::Matchers::BuiltIn::PositiveOperatorMatcher:0x007ff701ed0788>
        # Not yet implemented
        # ./spec/models/search_spec.rb:13
      Search #<RSpec::Matchers::BuiltIn::PositiveOperatorMatcher:0x007ff701ed0148>
        # Not yet implemented
        # ./spec/models/search_spec.rb:14
      Search #<RSpec::Matchers::BuiltIn::PositiveOperatorMatcher:0x007ff701ecfa40>
        # Not yet implemented
        # ./spec/models/search_spec.rb:15

    Finished in 0.4977 seconds
    12 examples, 0 failures, 12 pending
    Nets-Mac-Pro:mysite emai$ 

发生了什么事?

1 个答案:

答案 0 :(得分:2)

在你的例子中

it should { respond_to(:theme_ids) }

应该是

it { should respond_to(:theme_ids) }

同样更改所有示例。必须在传递给should方法的块中调用it