我在Rails 4中进行了以下模型测试:
要求'test_helper'
if ($this->getSubject() && $this->getSubject()->hasRole('ROLE_SUPER_ADMIN'))
以下是奖励模式:
class AwardTest < ActiveSupport::TestCase
def test_validity_of_year
# test for rejection of missing year
award = Award.new({name: "Test award, student_id: 1"})
assert !award.valid?
# test under lower boundary
award.year = 1979
assert !award.valid?
# lower boundary
award.year = 1980
assert award.valid?
# top boundary
award.year = Date.today.year
assert award.valid?
# top boundary case, award isn't valid for next year
award.year = Date.today.year + 1
assert !award.valid?
end
end
这是我的award_test.rb的输出
class Award < ApplicationRecord
belongs_to :student
validates_presence_of :name, :year
validates_inclusion_of :year, in: (1980..Date.today.year)
end
如果我在控制台中手动运行,我会...
bundle exec rake test TEST=test/models/award_test.rb
DEPRECATION WARNING: alias_method_chain is deprecated. Please, use Module#prepend instead. From module, you can access the original method using super. (called from included at .rvm/gems/ruby-2.2.2@rails/gems/turbolinks-2.5.3/lib/turbolinks/xhr_url_for.rb:7)
Run options: --seed 53138
# Running:
F
Failure:
AwardTest#test_validity_of_year [/Users/marklocklear/sandbox/students03/test/models/award_test.rb:16]:
Failed assertion, no message given.
bin/rails test test/models/award_test.rb:4
Finished in 0.042099s, 23.7538 runs/s, 71.2614 assertions/s.
1 runs, 3 assertions, 1 failures, 0 errors, 0 skips