Rspec测试没有说明它失败的原因

时间:2015-04-24 09:32:59

标签: ruby-on-rails rspec

这个测试没有说明它失败的原因:

    it "saves the new job in the database" do
      expect{
        post :create, booking: FactoryGirl.attributes_for(:booking)
      }.to change(Booking,:count).by(1)
    end

测试似乎很简单,功能在网站上有效。

UPD 作为参考,这是它正在测试的控制器:

  def create
    @booking = Booking.new(booking_params)
    @booking.save
    respond_with(@booking)
  end

工厂:

FactoryGirl.define do
  factory :booking do
    employer
    vehicle
    job_type
    location
    start "2015-04-23 09:00"
    ending "2015-04-23 15:00"
  end
end

UPD 这是rspec日志,带-b:

BookingsController
  as employer
    GET #new
      renders the :new template (PENDING: Not yet implemented)
      assigns a new job to @job (PENDING: Not yet implemented)
    GET #create
      with invalid attributes
        re-renders the :new template (PENDING: Not yet implemented)
        does not save in the database (PENDING: Not yet implemented)
      with valid attributes
        redirects to the show page (PENDING: Not yet implemented)
in populate_times
        saves the new job in the database (FAILED - 1)
    GET #create
      with invalid attributes
        re-renders the :new template (PENDING: Not yet implemented)
        does not save in the database (PENDING: Not yet implemented)
      with valid attributes
        redirects to the show page (PENDING: Not yet implemented)
        saves the new job in the database (PENDING: Not yet implemented)
    GET new
      renders the new template
    GET #show
      renders the :show template (PENDING: Not yet implemented)
      assigns the requested booking to @booking (PENDING: Not yet implemented)
  as visitor
    GET new
      redirects to new_employer_path

Pending: (Failures listed here are expected and do not affect your suite's status)

  1) BookingsController as employer GET #new renders the :new template
     # Not yet implemented
     # ./spec/controllers/booking_controller_spec.rb:60

  2) BookingsController as employer GET #new assigns a new job to @job
     # Not yet implemented
     # ./spec/controllers/booking_controller_spec.rb:59

  3) BookingsController as employer GET #create with invalid attributes re-renders the :new template
     # Not yet implemented
     # ./spec/controllers/booking_controller_spec.rb:38

  4) BookingsController as employer GET #create with invalid attributes does not save in the database
     # Not yet implemented
     # ./spec/controllers/booking_controller_spec.rb:37

  5) BookingsController as employer GET #create with valid attributes redirects to the show page
     # Not yet implemented
     # ./spec/controllers/booking_controller_spec.rb:33

  6) BookingsController as employer GET #create with invalid attributes re-renders the :new template
     # Not yet implemented
     # ./spec/controllers/booking_controller_spec.rb:71

  7) BookingsController as employer GET #create with invalid attributes does not save in the database
     # Not yet implemented
     # ./spec/controllers/booking_controller_spec.rb:70

  8) BookingsController as employer GET #create with valid attributes redirects to the show page
     # Not yet implemented
     # ./spec/controllers/booking_controller_spec.rb:66

  9) BookingsController as employer GET #create with valid attributes saves the new job in the database
     # Not yet implemented
     # ./spec/controllers/booking_controller_spec.rb:65

  10) BookingsController as employer GET #show renders the :show template
     # Not yet implemented
     # ./spec/controllers/booking_controller_spec.rb:55

  11) BookingsController as employer GET #show assigns the requested booking to @booking
     # Not yet implemented
     # ./spec/controllers/booking_controller_spec.rb:43


Failures:

  1) BookingsController as employer GET #create with valid attributes saves the new job in the database
     Failure/Error: expect{
       expected #count to have changed by 1, but was changed by 0
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-expectations-3.2.1/lib/rspec/expectations/fail_with.rb:29:in `fail_with'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-expectations-3.2.1/lib/rspec/expectations/handler.rb:40:in `handle_failure'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-expectations-3.2.1/lib/rspec/expectations/handler.rb:50:in `block in handle_matcher'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-expectations-3.2.1/lib/rspec/expectations/handler.rb:27:in `with_matcher'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-expectations-3.2.1/lib/rspec/expectations/handler.rb:48:in `handle_matcher'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-expectations-3.2.1/lib/rspec/expectations/expectation_target.rb:54:in `to'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-expectations-3.2.1/lib/rspec/expectations/expectation_target.rb:87:in `to'
     # ./spec/controllers/booking_controller_spec.rb:28:in `block (5 levels) in <top (required)>'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example.rb:177:in `instance_exec'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example.rb:177:in `block in run'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example.rb:385:in `block in with_around_and_singleton_context_hooks'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example.rb:343:in `block in with_around_example_hooks'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/hooks.rb:474:in `block in run'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/hooks.rb:614:in `block in run_around_example_hooks_for'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example.rb:247:in `call'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example.rb:247:in `call'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-rails-3.2.1/lib/rspec/rails/example/controller_example_group.rb:179:in `block (2 levels) in <module:ControllerExampleGroup>'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example.rb:333:in `instance_exec'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example.rb:333:in `instance_exec'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/hooks.rb:387:in `execute_with'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/hooks.rb:616:in `block (2 levels) in run_around_example_hooks_for'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example.rb:247:in `call'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example.rb:247:in `call'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-rails-3.2.1/lib/rspec/rails/adapters.rb:113:in `block (2 levels) in <module:MinitestLifecycleAdapter>'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example.rb:333:in `instance_exec'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example.rb:333:in `instance_exec'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/hooks.rb:387:in `execute_with'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/hooks.rb:616:in `block (2 levels) in run_around_example_hooks_for'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example.rb:247:in `call'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example.rb:247:in `call'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/hooks.rb:617:in `run_around_example_hooks_for'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/hooks.rb:474:in `run'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example.rb:343:in `with_around_example_hooks'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example.rb:385:in `with_around_and_singleton_context_hooks'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example.rb:174:in `run'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example_group.rb:549:in `block in run_examples'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example_group.rb:545:in `map'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example_group.rb:545:in `run_examples'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example_group.rb:512:in `run'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example_group.rb:513:in `block in run'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example_group.rb:513:in `map'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example_group.rb:513:in `run'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example_group.rb:513:in `block in run'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example_group.rb:513:in `map'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example_group.rb:513:in `run'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example_group.rb:513:in `block in run'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example_group.rb:513:in `map'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/example_group.rb:513:in `run'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:110:in `block (3 levels) in run_specs'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:110:in `map'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:110:in `block (2 levels) in run_specs'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/configuration.rb:1526:in `with_suite_hooks'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:109:in `block in run_specs'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/reporter.rb:62:in `report'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:108:in `run_specs'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:86:in `run'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:70:in `run'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/lib/rspec/core/runner.rb:38:in `invoke'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/gems/rspec-core-3.2.3/exe/rspec:4:in `<top (required)>'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/bin/rspec:23:in `load'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/bin/rspec:23:in `<main>'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/bin/ruby_executable_hooks:15:in `eval'
     # /Users/Will/.rvm/gems/ruby-2.0.0-p481@railstutorial_rails_4_0/bin/ruby_executable_hooks:15:in `<main>'

1 个答案:

答案 0 :(得分:0)

我无法添加注释导致我的声誉......但也许你应该尝试使用-b选项运行rspec来查看完整的回溯。并检测错误