discourse/spec/components/enum_spec.rb

39 lines
955 B
Ruby
Raw Normal View History

2013-03-01 16:05:39 -06:00
require 'spec_helper'
require 'email'
describe Enum do
let(:enum) { Enum.new(:jake, :finn, :princess_bubblegum, :peppermint_butler) }
describe ".[]" do
it "looks up a number by symbol" do
2015-01-09 10:34:37 -06:00
expect(enum[:princess_bubblegum]).to eq(3)
2013-03-01 16:05:39 -06:00
end
it "looks up a symbol by number" do
2015-01-09 10:34:37 -06:00
expect(enum[2]).to eq(:finn)
2013-03-01 16:05:39 -06:00
end
end
describe ".valid?" do
it "returns true if a key exists" do
2015-01-09 10:34:37 -06:00
expect(enum.valid?(:finn)).to eq(true)
2013-03-01 16:05:39 -06:00
end
it "returns false if a key does not exist" do
2015-01-09 10:34:37 -06:00
expect(enum.valid?(:obama)).to eq(false)
2013-03-01 16:05:39 -06:00
end
end
describe ".only" do
2013-03-01 16:05:39 -06:00
it "returns only the values we ask for" do
2015-01-09 10:34:37 -06:00
expect(enum.only(:jake, :princess_bubblegum)).to eq({ jake: 1, princess_bubblegum: 3 })
2013-03-01 16:05:39 -06:00
end
end
describe ".except" do
it "returns everything but the values we ask to delete" do
2015-01-09 10:34:37 -06:00
expect(enum.except(:jake, :princess_bubblegum)).to eq({ finn: 2, peppermint_butler: 4 })
2013-03-01 16:05:39 -06:00
end
end
end