spec/unit/a9n_spec.rb in a9n-0.6.2 vs spec/unit/a9n_spec.rb in a9n-0.7.0

- old
+ new

@@ -1,69 +1,69 @@ RSpec.describe A9n do subject { described_class } before { clean_singleton(subject) } after { clean_singleton(subject) } - describe ".env" do + describe '.env' do before do subject.instance_variable_set(:@env, nil) end - context "app_env is set" do + context 'app_env is set' do before do - expect(subject).to receive(:app).and_return(double(env: ::A9n::StringInquirer.new("dwarf_env"))).exactly(3).times + expect(subject).to receive(:app).and_return(double(env: ::A9n::StringInquirer.new('dwarf_env'))) expect(subject).to receive(:env_var).never end it do - expect(subject.env).to eq("dwarf_env") + expect(subject.env).to eq('dwarf_env') expect(subject.env.dwarf_env?).to eq(true) expect(subject.env.production?).to eq(false) end end - context "when APP_ENV is set" do + context 'when APP_ENV is set' do before do expect(subject).to receive(:app_env).and_return(nil) - expect(subject).to receive(:env_var).with("RAILS_ENV").and_return(nil) - expect(subject).to receive(:env_var).with("RACK_ENV").and_return(nil) - expect(subject).to receive(:env_var).with("APP_ENV").and_return("dwarf_env") + expect(subject).to receive(:env_var).with('RAILS_ENV').and_return(nil) + expect(subject).to receive(:env_var).with('RACK_ENV').and_return(nil) + expect(subject).to receive(:env_var).with('APP_ENV').and_return('dwarf_env') end it do - expect(subject.env).to eq("dwarf_env") + expect(subject.env).to eq('dwarf_env') expect(subject.env.dwarf_env?).to eq(true) expect(subject.env.production?).to eq(false) end end end - describe ".app" do - context "when rails not found" do + describe '.app' do + context 'when rails not found' do before do expect(subject).to receive(:rails_app).and_return(nil) end it do expect(subject.app).to be_nil end end - context "when rails app is being used" do - let(:app) { double(env: "test", root: "/apps/a9n") } + context 'when rails app is being used' do + let(:app) { double(env: 'test', root: '/apps/a9n') } before do expect(subject).to receive(:rails_app).and_return(app) end it do expect(subject.app).to eq(app) end end - context "when custom non-rails app is being used" do - let(:app) { double(env: "test", root: "/apps/a9n") } + context 'when custom non-rails app is being used' do + let(:app) { double(env: 'test', root: '/apps/a9n') } before do subject.app = app end @@ -71,64 +71,64 @@ expect(subject.app).to eq(app) end end end - describe ".root" do - context "when app is set" do - let(:app) { double(env: "test", root: "/apps/a9n") } + describe '.root' do + context 'when app is set' do + let(:app) { double(env: 'test', root: '/apps/a9n') } before do subject.app = app end - context "with custom path" do + context 'with custom path' do before do - subject.root = "/home/knapo/workspace/a9n" + subject.root = '/home/knapo/workspace/a9n' end it do - expect(subject.root).to eq(Pathname.new("/home/knapo/workspace/a9n")) + expect(subject.root).to eq(Pathname.new('/home/knapo/workspace/a9n')) end end - context "with local app path" do + context 'with local app path' do it do - expect(subject.root).to eq("/apps/a9n") + expect(subject.root).to eq('/apps/a9n') end end end - context "when app is not set" do + context 'when app is not set' do it do expect(subject.root).to eq(nil) end - context "when setting a custom path when is falsy" do + context 'when setting a custom path when is falsy' do before do - subject.root ||= "/home/knapo/workspace/a9n" + subject.root ||= '/home/knapo/workspace/a9n' end it do - expect(subject.root).to eq(Pathname.new("/home/knapo/workspace/a9n")) + expect(subject.root).to eq(Pathname.new('/home/knapo/workspace/a9n')) end end - context "when setting a custom path" do + context 'when setting a custom path' do before do - subject.root = "/home/knapo/workspace/a9n" + subject.root = '/home/knapo/workspace/a9n' end it do - expect(subject.root).to eq(Pathname.new("/home/knapo/workspace/a9n")) + expect(subject.root).to eq(Pathname.new('/home/knapo/workspace/a9n')) end end end end - describe ".rails_app" do - context "when defined" do + describe '.rails_app' do + context 'when defined' do before do Object.const_set(:Rails, Module.new) end after do @@ -138,58 +138,58 @@ it do expect(subject.rails_app).to be_kind_of(Module) end end - context "when not defined" do + context 'when not defined' do it do expect(subject.rails_app).to be_nil end end end - describe ".env_var" do + describe '.env_var' do before do - ENV["DWARF"] = "little dwarf" + ENV['DWARF'] = 'little dwarf' end it do - expect(subject.env_var("DWARF")).to eq("little dwarf") + expect(subject.env_var('DWARF')).to eq('little dwarf') end it do - expect(subject.env_var("IS_DWARF")).to be_nil + expect(subject.env_var('IS_DWARF')).to be_nil end end - describe ".default_files" do + describe '.default_files' do before do - subject.root = File.expand_path("../../../test_app", __FILE__) + subject.root = File.expand_path('../../test_app', __dir__) end it do - expect(subject.default_files[0]).to include("configuration.yml") + expect(subject.default_files[0]).to include('configuration.yml') expect(Pathname.new(subject.default_files[0])).to be_absolute - expect(subject.default_files[1]).to include("a9n/mandrill.yml") + expect(subject.default_files[1]).to include('a9n/mandrill.yml') expect(Pathname.new(subject.default_files[1])).to be_absolute end end - describe ".load" do + describe '.load' do before do - expect(described_class).to receive(:env).exactly(2).times.and_return("dev") - subject.root = "/apps/test_app" + expect(described_class).to receive(:env).exactly(2).times.and_return('dev') + subject.root = '/apps/test_app' files.each do |f, cfg| - expect(A9n::Loader).to receive(:new).with(f, kind_of(A9n::Scope), "dev").and_return(double(get: cfg)) + expect(A9n::Loader).to receive(:new).with(f, kind_of(A9n::Scope), 'dev').and_return(double(get: cfg)) end end - context "when no files given" do + context 'when no files given' do let(:files) do { - "/apps/test_app/config/file1.yml" => { host: "host1.com" }, - "/apps/test_app/config/dir/file2.yml" => { host: "host2.com" } + '/apps/test_app/config/file1.yml' => { host: 'host1.com' }, + '/apps/test_app/config/dir/file2.yml' => { host: 'host2.com' } } end before do expect(subject).to receive(:default_files).and_return(files.keys) @@ -199,19 +199,19 @@ it do expect(subject.load).to eq(files.values) end end - context "when custom files given" do + context 'when custom files given' do let(:given_files) do - ["file3.yml", "/apps/test_app/config/dir/file4.yml"] + ['file3.yml', '/apps/test_app/config/dir/file4.yml'] end let(:files) do { - "/apps/test_app/config/file3.yml" => { host: "host3.com" }, - "/apps/test_app/config/dir/file4.yml" => { host: "host4.com" } + '/apps/test_app/config/file3.yml' => { host: 'host3.com' }, + '/apps/test_app/config/dir/file4.yml' => { host: 'host4.com' } } end before do expect(subject).to receive(:default_files).never @@ -222,22 +222,22 @@ expect(subject.load(*given_files)).to eq(files.values) end end end - describe ".method_missing" do - context "when storage is empty" do + describe '.method_missing' do + context 'when storage is empty' do before do expect(subject).to receive(:load).once end it do expect(subject.storage).to be_empty expect { subject.whatever }.to raise_error(A9n::NoSuchConfigurationVariableError) end end - context "when storage is not empty" do + context 'when storage is not empty' do before do subject.storage[:whenever] = 'whenever' expect(subject).not_to receive(:load) end