spec/unit/settings_spec.rb in yousty-activeadmin-1.0.4.pre vs spec/unit/settings_spec.rb in yousty-activeadmin-1.0.5.pre

- old
+ new

@@ -1,25 +1,25 @@ -require 'spec_helper' +require 'rails_helper' describe ActiveAdmin::Settings do subject{ Class.new{ include ActiveAdmin::Settings } } - it{ should respond_to :setting } - it{ should respond_to :deprecated_setting } - it{ should respond_to :default_settings } + it{ is_expected.to respond_to :setting } + it{ is_expected.to respond_to :deprecated_setting } + it{ is_expected.to respond_to :default_settings } describe "class API" do it "should create settings" do subject.setting :foo, 'bar' - subject.default_settings[:foo].should eq 'bar' + expect(subject.default_settings[:foo]).to eq 'bar' end it "should create deprecated settings" do - ActiveAdmin::Deprecation.should_receive(:deprecate).twice + expect(ActiveAdmin::Deprecation).to receive(:deprecate).twice subject.deprecated_setting :baz, 32 - subject.default_settings[:baz].should eq 32 + expect(subject.default_settings[:baz]).to eq 32 end end describe "instance API" do @@ -28,20 +28,20 @@ subject.deprecated_setting :baz, 32 end let(:instance) { subject.new } it "should have access to a default value" do - instance.foo.should eq 'bar' + expect(instance.foo).to eq 'bar' instance.foo = 'qqq' - instance.foo.should eq 'qqq' + expect(instance.foo).to eq 'qqq' end it "should have access to a deprecated value" do - ActiveAdmin::Deprecation.should_receive(:warn).exactly(3).times - instance.baz.should eq 32 + expect(ActiveAdmin::Deprecation).to receive(:warn).exactly(3).times + expect(instance.baz).to eq 32 instance.baz = [45] - instance.baz.should eq [45] + expect(instance.baz).to eq [45] end end end @@ -53,36 +53,66 @@ include ActiveAdmin::Settings include ActiveAdmin::Settings::Inheritance end end - it{ should respond_to :settings_inherited_by } - it{ should respond_to :inheritable_setting } - it{ should respond_to :deprecated_inheritable_setting } + it{ is_expected.to respond_to :settings_inherited_by } + it{ is_expected.to respond_to :inheritable_setting } + it{ is_expected.to respond_to :deprecated_inheritable_setting } let(:heir) { Class.new } before do subject.settings_inherited_by heir end describe "class API" do it "should add setting to an heir" do subject.inheritable_setting :one, 2 - heir.default_settings[:one].should eq 2 + expect(heir.default_settings[:one]).to eq 2 end it "should add deprecated setting to an heir" do - ActiveAdmin::Deprecation.should_receive(:deprecate).exactly(4).times + expect(ActiveAdmin::Deprecation).to receive(:deprecate).exactly(4).times subject.deprecated_inheritable_setting :three, 4 - heir.default_settings[:three].should eq 4 + expect(heir.default_settings[:three]).to eq 4 end end describe "instance API" do - before{ subject.inheritable_setting :left, :right } - it "should work" do - heir.new.left.should eq :right + describe "the setter `config.left =`" do + before{ subject.inheritable_setting :left, :right } + it "should work" do + config = heir.new + config.left = :none + expect(config.left).to eq :none + end + end + + describe "the getter `config.left`" do + before{ subject.inheritable_setting :left, :right } + it "should work" do + expect(heir.new.left).to eq :right + end + end + + describe "the getter with question-mark `config.left?`" do + { + "nil" => [nil, false], + "false" => [false, false], + "true" => [true, true], + "string" => ["string", true], + "empty string" => ["", false], + "array" => [[1, 2], true], + "empty array" => [[], false] + }.each do |context, (value, result)| + context "with a #{context} value" do + before{ subject.inheritable_setting :left, value } + it "should be #{result}" do + expect(heir.new.left?).to eq result + end + end + end end end end