Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ source "http://rubygems.org"
# Add dependencies to develop your gem here.
# Include everything needed to run rake, tests, features, etc.
group :development do
gem "rspec"
gem "bundler", "~> 1.0.0"
gem "jeweler", "~> 1.5.1"
gem "rcov", ">= 0"
gem "ruby-debug"
gem 'rspec'
gem 'bundler'
gem 'jeweler'
gem 'simplecov'
gem 'pry-byebug'
end
111 changes: 86 additions & 25 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,36 +1,97 @@
GEM
remote: http://rubygems.org/
specs:
columnize (0.3.2)
diff-lcs (1.1.2)
git (1.2.5)
jeweler (1.5.1)
bundler (~> 1.0.0)
addressable (2.5.0)
public_suffix (~> 2.0, >= 2.0.2)
builder (3.2.3)
byebug (9.0.6)
coderay (1.1.1)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
diff-lcs (1.3)
docile (1.1.5)
faraday (0.9.2)
multipart-post (>= 1.2, < 3)
git (1.3.0)
github_api (0.11.3)
addressable (~> 2.3)
descendants_tracker (~> 0.0.1)
faraday (~> 0.8, < 0.10)
hashie (>= 1.2)
multi_json (>= 1.7.5, < 2.0)
nokogiri (~> 1.6.0)
oauth2
hashie (3.5.1)
highline (1.7.8)
jeweler (2.3.3)
builder
bundler (>= 1.0)
git (>= 1.2.5)
github_api (~> 0.11.0)
highline (>= 1.6.15)
nokogiri (>= 1.5.10)
psych (~> 2.2)
rake
linecache (0.43)
rake (0.8.7)
rcov (0.9.9)
rspec (2.3.0)
rspec-core (~> 2.3.0)
rspec-expectations (~> 2.3.0)
rspec-mocks (~> 2.3.0)
rspec-core (2.3.0)
rspec-expectations (2.3.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.3.0)
ruby-debug (0.10.4)
columnize (>= 0.1)
ruby-debug-base (~> 0.10.4.0)
ruby-debug-base (0.10.4)
linecache (>= 0.3)
rdoc
semver2
json (2.0.3)
jwt (1.5.6)
method_source (0.8.2)
mini_portile2 (2.1.0)
multi_json (1.12.1)
multi_xml (0.6.0)
multipart-post (2.0.0)
nokogiri (1.6.8.1)
mini_portile2 (~> 2.1.0)
oauth2 (1.3.0)
faraday (>= 0.8, < 0.11)
jwt (~> 1.0)
multi_json (~> 1.3)
multi_xml (~> 0.5)
rack (>= 1.2, < 3)
pry (0.10.4)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
pry-byebug (3.4.2)
byebug (~> 9.0)
pry (~> 0.10)
psych (2.2.2)
public_suffix (2.0.5)
rack (2.0.1)
rake (12.0.0)
rdoc (5.0.0)
rspec (3.5.0)
rspec-core (~> 3.5.0)
rspec-expectations (~> 3.5.0)
rspec-mocks (~> 3.5.0)
rspec-core (3.5.4)
rspec-support (~> 3.5.0)
rspec-expectations (3.5.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.5.0)
rspec-mocks (3.5.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.5.0)
rspec-support (3.5.0)
semver2 (3.4.2)
simplecov (0.13.0)
docile (~> 1.1.0)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.0)
slop (3.6.0)
thread_safe (0.3.5)

PLATFORMS
ruby

DEPENDENCIES
bundler (~> 1.0.0)
jeweler (~> 1.5.1)
rcov
bundler
jeweler
pry-byebug
rspec
ruby-debug
simplecov

BUNDLED WITH
1.14.3
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.6
0.2.0
2 changes: 1 addition & 1 deletion lib/setting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def value_for(key, args = [])
v = yield(v, args)
end

if v.is_a?(Fixnum) && bool
if v.is_a?(Integer) && bool
v.to_i > 0
else
v
Expand Down
105 changes: 53 additions & 52 deletions spec/mc_settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,60 @@
describe Setting do
subject { Setting }

context "Test with stubs" do
context 'Test with stubs' do
before :each do
stub_setting_files
subject.reload(
:path => "config/settings",
:files => ["default.yml", "environments/test.yml"],
:path => 'config/settings',
:files => ['default.yml', 'environments/test.yml'],
:local => true)
end

it 'should return test specific values' do
subject.available_settings['one'].should == "test"
subject.one.should == "test"
subject['one'].should == "test"
expect(subject.available_settings['one']).to eq 'test'
expect(subject.one).to eq 'test'
expect(subject['one']).to eq 'test'
end

it "should handle custom values overriding everything else" do
subject.seven.should == "seven from custom"
it 'should handle custom values overriding everything else' do
expect(subject.seven).to eq 'seven from custom'
end

it "handles multiple values" do
subject[:six].should == {"default"=>"default value", "extra"=>"recursively overriden", "deep_level"=>{"value"=>"even deeper level"}}
subject.available_settings['six']['default'].should == "default value"
subject.seven.should == "seven from custom"
expect(subject[:six]).to eq({"default"=>"default value", "extra"=>"recursively overriden", "deep_level"=>{"value"=>"even deeper level"}})
expect(subject.available_settings['six']['default']).to eq "default value"
expect(subject.seven).to eq "seven from custom"
end

it "handles default key" do
subject.default_setting.should == 1
subject['seven']['default'].should == "seven from custom"
expect(subject.default_setting).to eq 1
expect(subject['seven']['default']).to eq "seven from custom"
end

it "should handle empty strings" do
subject.empty.should == ""
expect(subject.empty).to eq ""
end

it "should responds to ? mark" do
subject.autologin?.should == true
expect(subject.autologin?).to eq true
end

it "should returns false correctly" do
subject.flag_false.should be(false)
expect(subject.flag_false).to be(false)
end

it "should merge keys recursivelly" do
subject.six(:extra).should == "recursively overriden"
subject.six(:deep_level, :value).should == "even deeper level"
expect(subject.six(:extra)).to eq "recursively overriden"
expect(subject.six(:deep_level, :value)).to eq "even deeper level"
end

it "should create keys if it does not exist" do
subject.test_specific.should == "exist"
expect(subject.test_specific).to eq "exist"
end

context "working with arrays" do
it "should replace the whole array instead of appending new values" do
subject.nested_array.should == ['first', 'four', 'five']
expect(subject.nested_array).to eq ['first', 'four', 'five']
end
end
end
Expand All @@ -64,7 +64,7 @@
it "should keep its values" do
3.times do |time|
Thread.new {
subject.available_settings.shoud_not be_empty
expect(subject.available_settings).to_not be_empty
}
end
end
Expand All @@ -79,28 +79,28 @@
end

it 'should support [] syntax' do
subject['tax']['default'].should == 0.0
subject['tax'].should == { 'default' => 0.0, 'california' => 7.5 }
expect(subject['tax']['default']).to eq 0.0
expect(subject['tax']).to eq({ 'default' => 0.0, 'california' => 7.5 })
end

it 'should support method invocation syntax' do
subject.tax.should == 0.0
expect(subject.tax).to eq 0.0

subject.tax(:default).should == subject.tax
subject.tax('default').should == subject.tax
subject.tax(:california).should == 7.5
expect(subject.tax(:default)).to eq subject.tax
expect(subject.tax('default')).to eq subject.tax
expect(subject.tax(:california)).to eq 7.5

subject.states.should == ['CA', 'WA', 'NY']
subject.states(:default).should == subject.states
subject.states(:ship_to).should == ['CA', 'NY']
expect(subject.states).to eq ['CA', 'WA', 'NY']
expect(subject.states(:default)).to eq subject.states
expect(subject.states(:ship_to)).to eq ['CA', 'NY']
end

it 'should correctly process Boolean values' do
subject.boolean_true?.should be(true)
subject.boolean_true.should == 4
subject.boolean_false?.should be(false)
subject.boolean_false?(:default).should be(false)
subject.boolean_false?(:negated).should be(true)
expect(subject.boolean_true?).to be(true)
expect(subject.boolean_true).to eq 4
expect(subject.boolean_false?).to be(false)
expect(subject.boolean_false?(:default)).to be(false)
expect(subject.boolean_false?(:negated)).to be(true)
end
end

Expand All @@ -113,16 +113,16 @@
end

it 'should override colors with Joes and support nested hashes' do
subject.color.should == :grey # default
subject.color(:pants).should == :purple # default
expect(subject.color).to eq :grey # default
expect(subject.color(:pants)).to eq :purple # default

subject.color(:pants, :school).should == :blue # in sample
subject.color(:pants, :favorite).should == :orange # joes override
expect(subject.color(:pants, :school)).to eq :blue # in sample
expect(subject.color(:pants, :favorite)).to eq :orange # joes override

subject.color(:shorts, :school).should == :black # in sample
subject.color(:shorts, :favorite).should == :white # joe's override
expect(subject.color(:shorts, :school)).to eq :black # in sample
expect(subject.color(:shorts, :favorite)).to eq :white # joe's override

subject.color(:shorts).should == :stripes # joe's override of default
expect(subject.color(:shorts)).to eq :stripes # joe's override of default
end

end
Expand All @@ -134,13 +134,13 @@
)
end
it "should build correct tree with arrays and default values " do
subject.shipping_config.should == "Defaulted"
subject.shipping_config(:domestic, :non_shippable_regions).first.should == "US-AS"
subject.shipping_config(:international, :service).should == 'Foo'
subject.shipping_config(:international, :countries).size.should > 0
subject.shipping_config(:international, :shipping_carrier).should == 'Bar'
expect(subject.shipping_config).to eq "Defaulted"
expect(subject.shipping_config(:domestic, :non_shippable_regions).first).to eq "US-AS"
expect(subject.shipping_config(:international, :service)).to eq 'Foo'
expect(subject.shipping_config(:international, :countries).size).to be > 0
expect(subject.shipping_config(:international, :shipping_carrier)).to eq 'Bar'
#backward compatibility:
subject.shipping_config(:domestic)['non_shippable_regions'].size.should > 0
expect(subject.shipping_config(:domestic)['non_shippable_regions'].size).to be > 0
end
end

Expand All @@ -151,10 +151,11 @@
:files => ['shipping.yml']
)
end
it "should interpret ruby code and put correct values" do
subject.shipping_config.should == "Defaulted"
subject.number == 5
subject.stringified == "stringified"

it 'should interpret ruby code and put correct values' do
expect(subject.shipping_config).to eq 'Defaulted'
expect(subject.number).to eq 5
expect(subject.stringified).to eq 'stringified'
end
end
end
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'rspec'
require 'mc-settings'
require 'ruby-debug'
require 'pry-byebug'

# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
Expand Down
16 changes: 8 additions & 8 deletions spec/support/settings_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ def stub_setting_files
default: "seven from custom"
CONTENT

File.stub!(:exists?).and_return(true)
File.stub!(:exists?).with("config/settings/environments/development.yml").and_return(false)
IO.stub!(:read).with("config/settings/default.yml").and_return(defaults)
IO.stub!(:read).with("config/settings/environments/test.yml").and_return(test)
IO.stub!(:read).with("config/settings/local/custom.yml").and_return(custom)
IO.stub!(:read).with("config/settings/local/empty.yml").and_return(empty)
allow(File).to receive(:exists?).and_return(true)
allow(File).to receive(:exists?).with("config/settings/environments/development.yml").and_return(false)
allow(IO).to receive(:read).with("config/settings/default.yml").and_return(defaults)
allow(IO).to receive(:read).with("config/settings/environments/test.yml").and_return(test)
allow(IO).to receive(:read).with("config/settings/local/custom.yml").and_return(custom)
allow(IO).to receive(:read).with("config/settings/local/empty.yml").and_return(empty)

Dir.stub!(:glob).and_return(["config/settings/local/empty.yml", "config/settings/local/custom.yml"])
end
allow(Dir).to receive(:glob).and_return(["config/settings/local/empty.yml", "config/settings/local/custom.yml"])
end