2013-03-01 17:05:39 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
require 'email'
|
|
|
|
|
|
|
|
describe Enum do
|
|
|
|
let(:enum) { Enum.new(:jake, :finn, :princess_bubblegum, :peppermint_butler) }
|
|
|
|
|
2013-03-02 02:40:32 -05:00
|
|
|
describe ".[]" do
|
|
|
|
it "looks up a number by symbol" do
|
2013-03-01 17:05:39 -05:00
|
|
|
enum[:princess_bubblegum].should == 3
|
|
|
|
end
|
|
|
|
|
2013-03-02 02:40:32 -05:00
|
|
|
it "looks up a symbol by number" do
|
2013-03-01 17:05:39 -05:00
|
|
|
enum[2].should == :finn
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-02 02:40:32 -05:00
|
|
|
describe ".valid?" do
|
|
|
|
it "returns true if a key exists" do
|
|
|
|
enum.valid?(:finn).should be_true
|
2013-03-01 17:05:39 -05:00
|
|
|
end
|
|
|
|
|
2013-03-02 02:40:32 -05:00
|
|
|
it "returns false if a key does not exist" do
|
|
|
|
enum.valid?(:obama).should be_false
|
2013-03-01 17:05:39 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-02 02:40:32 -05:00
|
|
|
describe ".only" do
|
2013-03-01 17:05:39 -05:00
|
|
|
it "returns only the values we ask for" do
|
2013-03-02 02:40:32 -05:00
|
|
|
enum.only(:jake, :princess_bubblegum).should == { jake: 1, princess_bubblegum: 3 }
|
2013-03-01 17:05:39 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-02 02:40:32 -05:00
|
|
|
describe ".except" do
|
|
|
|
it "returns everything but the values we ask to delete" do
|
|
|
|
enum.except(:jake, :princess_bubblegum).should == { finn: 2, peppermint_butler: 4 }
|
2013-03-01 17:05:39 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|