簡體   English   中英

Rspec單元測試用例失敗

[英]Rspec unit test case getting failed

我在spec / models / season_spec.rb文件中寫了一些Rspec測試用例。 他們是: -

require 'spec_helper'

describe Season do

  it 'should not be without name' do
    Season.new(:name=>nil,:number_of_weeks=>'3',:start_date=>'2012-02-07',:user_id=>'113').should_not be_valid
  end

  it 'should not be without number of weeks' do
    Season.new(:name=>'Apurva',:number_of_weeks=>nil,:start_date=>'2012-02-07',:user_id=>'113').should_not be_valid
  end

  it 'should not be without start_date' do
    Season.new(:name=>'Apurva',:number_of_weeks=>'3',:start_date=>nil,:user_id=>'113').should_not be_valid
  end

  it 'should not be without user_id' do
    Season.new(:name=>'Apurva',:number_of_weeks=>'3',:start_date=>'2012-02-07',:user_id=>nil).should_not be_valid
  end

  it 'should be with valid attributes' do
    Season.new(:name=>'Apurva',:number_of_weeks=>'3',:start_date=>'2012-02-07',:user_id=>'113').should be_valid
  end
end

在我的模型中,我已將這些字段驗證為: -

class Season < ActiveRecord::Base

  validates_presence_of :name,:number_of_weeks,:start_date,:user_id
end

但是測試用例仍然失敗了。 它給了我以下輸出: -

/usr/lib/ruby/gems/1.8/gems/bundler-1.0.21/lib/bundler/runtime.rb:138: warning: Insecure world writable dir /usr/lib/ruby/gems/1.8 in PATH, mode 040777
FFFFF

Failures:

/usr/lib/ruby/gems/1.8/gems/rspec-core-2.8.0/lib/rspec/core/formatters/base_text_formatter.rb:165:in `pending_fixed?': undefined method `pending_fixed?' for #<ActiveRecord::StatementInvalid:0xb6cd03c8> (NoMethodError)
    from /usr/lib/ruby/gems/1.8/gems/rspec-core-2.8.0/lib/rspec/core/formatters/base_text_formatter.rb:19:in `dump_failures'
    from /usr/lib/ruby/gems/1.8/bundler/gems/rails-27357a6965eb/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:473:in `each_with_index'
    from /usr/lib/ruby/gems/1.8/gems/rspec-core-2.8.0/lib/rspec/core/formatters/base_text_formatter.rb:17:in `each'
    from /usr/lib/ruby/gems/1.8/gems/rspec-core-2.8.0/lib/rspec/core/formatters/base_text_formatter.rb:17:in `each_with_index'
    from /usr/lib/ruby/gems/1.8/gems/rspec-core-2.8.0/lib/rspec/core/formatters/base_text_formatter.rb:17:in `dump_failures'
    from /usr/lib/ruby/vendor_ruby/rspec/core/reporter.rb:75:in `send'
    from /usr/lib/ruby/vendor_ruby/rspec/core/reporter.rb:75:in `notify'
    from /usr/lib/ruby/vendor_ruby/rspec/core/reporter.rb:74:in `each'
    from /usr/lib/ruby/vendor_ruby/rspec/core/reporter.rb:74:in `notify'
    from /usr/lib/ruby/vendor_ruby/rspec/core/reporter.rb:23:in `conclude'
    from /usr/lib/ruby/vendor_ruby/rspec/core/reporter.rb:14:in `report'
    from /usr/lib/ruby/vendor_ruby/rspec/core/command_line.rb:24:in `run'
    from /usr/lib/ruby/vendor_ruby/rspec/core/runner.rb:55:in `run_in_process'
    from /usr/lib/ruby/vendor_ruby/rspec/core/runner.rb:46:in `run'
    from /usr/lib/ruby/vendor_ruby/rspec/core/runner.rb:10:in `autorun'
    from /usr/bin/rspec:4

首先, 'should not be without name'規范中有一個拼寫錯誤。 請在此處或在您的代碼中輸入查詢時檢查這是否只是一個拼寫錯誤。

其次,這些測試毫無意義,因為這里已經測試過該代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM