Given this code:
field :start_now, type: Boolean, :default => true
field :time_zone
validates :time_zone, inclusion: {
in: ActiveSupport::TimeZone.zones_map.keys
}, unless: :start_now?
I have created this rspec test, but it's long and not DRY. And the only reason to be like this is because of the "unless" condition:
describe "#time_zone" do
context "scheduled" do
before :each do
subject.start_now = false
end
it { is_expected.to validate_inclusion_of(:time_zone).in_array(ActiveSupport::TimeZone.zones_map.keys) }
end
context "run now" do
before :each do
subject.start_now = true
end
it { is_expected.not_to validate_inclusion_of(:time_zone).in_array(ActiveSupport::TimeZone.zones_map.keys) }
end
end
Is there any shorter way to do this?