In my device model, I have
enum device_type: { ios: 1 , android: 2 } validates :device_type, presence: true, inclusion: { in: device_types.keys }
And in my device_spec.rb , I am writing several tests for this, for example
describe 'validations' do subject { FactoryGirl.build(:device) } it { is_expected.to allow_values('ios', 'android').for(:device_type) } it { is_expected.to validate_inclusion_of(:device_type).in_array(%w(ios android)) } it { is_expected.not_to allow_value('windows').for(:device_type) } end
When I ran rspec, the allow_values ββtest allow_values('ios', 'android') was passed, but the other two were unsuccessful.
1) The device must ensure the inclusion of device_type in ["ios", "android"]
Error / Error: this is {is_expected.to validate_inclusion_of (: device_type) .in_array (% w (ios android))}
ArgumentError: '123456789' is not a valid device_type
2) The device should not allow the installation of the device_type parameter in "windows"
Error / Error: this is {is_expected.not_to allow_value ('windows'). for (: device_type)}
ArgumentError: 'windows' is not a valid device_type
"This is an invalid device_type type," but why did these tests fail?