ruby on rails - Boolean validation rSpec tests -


i'm having trouble writing test make sure field :on_ride_photo boolean value.

my validates call:

  validates :on_ride_photo,     inclusion: [true, false] 

my tests:

it { should validate_presence_of(:on_ride_photo) } { should ensure_inclusion_of(:on_ride_photo).in_array([true, false]) } { should_not allow_value(4).for(:on_ride_photo) } { should_not allow_value('lots').for(:on_ride_photo) } 

factory:

  factory :coaster     association :park     name 'nemesis'     speed 60     height 60     length 160     inversions 4     on_ride_photo true     lat 52.98694     lng -1.88284     dates_ridden '24th jul 2013:4, 9th aug 2009:7'     powered false   end 

errors:

failures:

1) coaster validations should not allow on_ride_photo set "lots" failure/error: { should_not allow_value('lots').for(:on_ride_photo) } expected errors when on_ride_photo set "lots", got no errors # ./spec/models/coaster_spec.rb:98:in `block (3 levels) in '

2) coaster validations should not allow on_ride_photo set 4 failure/error: { should_not allow_value(4).for(:on_ride_photo) } expected errors when on_ride_photo set 4, got no errors # ./spec/models/coaster_spec.rb:97:in `block (3 levels) in '

3) coaster validations should not allow powered set "yes" failure/error: { should_not allow_value('yes').for(:powered) } expected errors when powered set "yes", got no errors # ./spec/models/coaster_spec.rb:102:in `block (3 levels) in '

4) coaster validations should require on_ride_photo set failure/error: { should validate_presence_of(:on_ride_photo) } expected errors include "can't blank" when on_ride_photo set nil, got errors: ["on_ride_photo not included in list (nil)"] # ./spec/models/coaster_spec.rb:95:in `block (3 levels) in '

5) coaster validations should ensure inclusion of powered in [true, false] failure/error: { should ensure_inclusion_of(:powered).in_array([true, false]) } [true, false] doesn't match array in validation # ./spec/models/coaster_spec.rb:100:in `block (3 levels) in '

6) coaster validations should not allow powered set 4 failure/error: { should_not allow_value(4).for(:powered) } expected errors when powered set 4, got no errors # ./spec/models/coaster_spec.rb:101:in `block (3 levels) in '

7) coaster validations should ensure inclusion of on_ride_photo in [true, false] failure/error: { should ensure_inclusion_of(:on_ride_photo).in_array([true, false]) } [true, false] doesn't match array in validation # ./spec/models/coaster_spec.rb:96:in `block (3 levels) in '

:powered should boolean field have same tests therefore reason why showing in test errors too.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -