diff --git a/metaforce.gemspec b/metaforce.gemspec index ee0cbce..4f526ab 100644 --- a/metaforce.gemspec +++ b/metaforce.gemspec @@ -23,13 +23,14 @@ EOL s.add_dependency 'savon', '~> 1.2.0' s.add_dependency 'rubyzip', '~> 1.0' - s.add_dependency 'activesupport' + s.add_dependency 'activesupport', RUBY_VERSION < "1.9.3" ? [">= 2", "< 4"] : ">= 2" s.add_dependency 'hashie', '~> 1.2.0' s.add_dependency 'thor', '~> 0.16.0' s.add_dependency 'listen', '~> 0.6.0' s.add_dependency 'rb-fsevent', '~> 0.9.1' s.add_development_dependency 'rake' + s.add_development_dependency 'rspec-its', '~>1.0.0pre' s.add_development_dependency 'rspec' s.add_development_dependency 'webmock' s.add_development_dependency 'savon_spec', '~> 1.3.0' diff --git a/spec/lib/cli_spec.rb b/spec/lib/cli_spec.rb index 15fdc6c..4d6f090 100644 --- a/spec/lib/cli_spec.rb +++ b/spec/lib/cli_spec.rb @@ -3,9 +3,9 @@ describe Metaforce::CLI do before do - Metaforce::Client.any_instance.stub(:deploy).and_return(double('deploy job').as_null_object) - Metaforce::Client.any_instance.stub(:retrieve).and_return(double('retrieve job').as_null_object) - subject.stub(:config).and_return(nil) + allow_any_instance_of(Metaforce::Client).to receive(:deploy).and_return(double('deploy job').as_null_object) + allow_any_instance_of(Metaforce::Client).to receive(:retrieve).and_return(double('retrieve job').as_null_object) + allow(subject).to receive(:config).and_return(nil) end describe 'credentials' do @@ -16,8 +16,8 @@ it 'uses supplied credentials from command line' do subject.options = options - Metaforce.should_receive(:new).with(indifferent_hash(options).slice(:username, :password, :security_token)).and_call_original - output.should include('Deploying: ./path') + expect(Metaforce).to receive(:new).with(indifferent_hash(options).slice(:username, :password, :security_token)).and_call_original + expect(output).to include('Deploying: ./path') end end @@ -27,9 +27,9 @@ it 'uses credentials from the config file' do subject.options = options - subject.stub(:config).and_return('production' => config) - Metaforce.should_receive(:new).with(indifferent_hash(config)).and_call_original - output.should include('Deploying: ./path') + allow(subject).to receive(:config).and_return('production' => config) + expect(Metaforce).to receive(:new).with(indifferent_hash(config)).and_call_original + expect(output).to include('Deploying: ./path') end end end diff --git a/spec/lib/client_spec.rb b/spec/lib/client_spec.rb index 6cdd6fb..ba52861 100644 --- a/spec/lib/client_spec.rb +++ b/spec/lib/client_spec.rb @@ -18,8 +18,8 @@ %w[services metadata].each do |type| context "when the #{type} client responds to method" do it 'proxies to the method' do - client.send(type.to_sym).should_receive(:respond_to?).with(:foobar, false).and_return(true) - client.send(type.to_sym).should_receive(:foobar) + allow(client.send(type.to_sym)).to receive(:foobar) + expect(client.send(type.to_sym)).to receive(:respond_to?).with(:foobar, false).and_return(true) client.foobar end end diff --git a/spec/lib/job/deploy_spec.rb b/spec/lib/job/deploy_spec.rb index 8051472..691c8be 100644 --- a/spec/lib/job/deploy_spec.rb +++ b/spec/lib/job/deploy_spec.rb @@ -10,8 +10,8 @@ context 'when the path is a file' do before do - client.should_receive(:_deploy).with(/^UEsDBA.*/, {}).and_return(Hashie::Mash.new(id: '1234')) - client.should_receive(:status).any_number_of_times.and_return(Hashie::Mash.new(done: true, state: 'Completed')) + expect(client).to receive(:_deploy).with(/^UEsDBA.*/, {}).and_return(Hashie::Mash.new(id: '1234')) + expect(client).to receive(:status).at_least(:once).and_return(Hashie::Mash.new(done: true, state: 'Completed')) end it { should eq job } @@ -20,8 +20,8 @@ context 'when the path is a directory' do before do - client.should_receive(:_deploy).with(/.*1stwAAAJI.*/, {}).and_return(Hashie::Mash.new(id: '1234')) - client.should_receive(:status).any_number_of_times.and_return(Hashie::Mash.new(done: true, state: 'Completed')) + expect(client).to receive(:_deploy).with(/.*1stwAAAJI.*/, {}).and_return(Hashie::Mash.new(id: '1234')) + expect(client).to receive(:status).at_least(:once).and_return(Hashie::Mash.new(done: true, state: 'Completed')) end let(:path) { File.expand_path('../../../fixtures', __FILE__) } @@ -34,7 +34,7 @@ let(:response) { Hashie::Mash.new(success: true) } before do - client.should_receive(:status).with(job.id, :deploy).and_return(response) + expect(client).to receive(:status).with(job.id, :deploy).and_return(response) end subject { job.result } @@ -45,10 +45,10 @@ let(:response) { Hashie::Mash.new(success: true) } before do - client.should_receive(:status).with(job.id, :deploy).and_return(response) + expect(client).to receive(:status).with(job.id, :deploy).and_return(response) end subject { job.success? } - it { should be_true } + it { should be_truthy } end end diff --git a/spec/lib/job/retrieve_spec.rb b/spec/lib/job/retrieve_spec.rb index d806a99..345f3f0 100644 --- a/spec/lib/job/retrieve_spec.rb +++ b/spec/lib/job/retrieve_spec.rb @@ -1,4 +1,5 @@ require 'spec_helper' +require 'base64' describe Metaforce::Job::Retrieve do let(:client) { double('metadata client') } @@ -8,7 +9,7 @@ let(:response) { Hashie::Mash.new(success: true) } before do - client.should_receive(:status).with(job.id, :retrieve).and_return(response) + expect(client).to receive(:status).with(job.id, :retrieve).and_return(response) end subject { job.result } @@ -16,13 +17,15 @@ end describe '.zip_file' do - let(:response) { Hashie::Mash.new(success: true, zip_file: 'foobar') } + zip_file_content = 'foobar' + let(:response) { Hashie::Mash.new(success: true, zip_file: zip_file_content) } before do - client.should_receive(:status).with(job.id, :retrieve).and_return(response) + expect(client).to receive(:status).with(job.id, :retrieve).and_return(response) end subject { job.zip_file } - it { should eq "~\x8A\e" } + #it { should eq "~\x8A\e" } + it { should eq Base64.decode64(zip_file_content) } end end diff --git a/spec/lib/job_spec.rb b/spec/lib/job_spec.rb index e4686c2..f19d914 100644 --- a/spec/lib/job_spec.rb +++ b/spec/lib/job_spec.rb @@ -6,7 +6,7 @@ describe '.perform' do it 'starts a heart beat' do - job.should_receive(:start_heart_beat) + expect(job).to receive(:start_heart_beat) job.perform end end @@ -19,39 +19,39 @@ job.instance_variable_set(:@id, '1234') end - it { should be_true } + it { should be_truthy } end context 'when .perform has not been called and no @id has been set' do - it { should be_false } + it { should be_falsey } end end describe '.on_complete' do it 'allows the user to register an on_complete callback' do - client.should_receive(:status).any_number_of_times.and_return(Hashie::Mash.new(done: true, state: 'Completed')) + expect(client).to receive(:status).and_return(Hashie::Mash.new(done: true, state: 'Completed')) called = false block = lambda { |job| called = true } job.on_complete &block job.perform - expect(called).to be_true + expect(called).to be_truthy end end describe '.on_error' do it 'allows the user to register an on_error callback' do - client.should_receive(:status).any_number_of_times.and_return(Hashie::Mash.new(done: true, state: 'Error')) + expect(client).to receive(:status).and_return(Hashie::Mash.new(done: true, state: 'Error')) called = false block = lambda { |job| called = true } job.on_error &block job.perform - expect(called).to be_true + expect(called).to be_truthy end end describe '.status' do before do - client.should_receive(:status) + expect(client).to receive(:status) end subject { job.status } @@ -63,18 +63,18 @@ context 'when done' do before do - client.should_receive(:status).and_return(Hashie::Mash.new(done: true)) + expect(client).to receive(:status).and_return(Hashie::Mash.new(done: true)) end - it { should be_true } + it { should be_truthy } end context 'when not done' do before do - client.should_receive(:status).and_return(Hashie::Mash.new(done: false)) + expect(client).to receive(:status).and_return(Hashie::Mash.new(done: false)) end - it { should be_false } + it { should be_falsey } end end @@ -83,7 +83,7 @@ context 'when done' do before do - client.should_receive(:status).and_return(Hashie::Mash.new(done: true, state: 'Completed')) + expect(client).to receive(:status).and_return(Hashie::Mash.new(done: true, state: 'Completed')) end it { should eq 'Completed' } @@ -91,21 +91,21 @@ context 'when not done' do before do - client.should_receive(:status).once.and_return(Hashie::Mash.new(done: false)) + expect(client).to receive(:status).once.and_return(Hashie::Mash.new(done: false)) end - it { should be_false } + it { should be_falsey } end end %w[Queued InProgress Completed Error].each do |state| describe ".#{state.underscore}?" do before do - client.should_receive(:status).and_return(Hashie::Mash.new(done: true, state: state)) + expect(client).to receive(:status).and_return(Hashie::Mash.new(done: true, state: state)) end subject { job.send(:"#{state.underscore}?") } - it { should be_true } + it { should be_truthy } end end end diff --git a/spec/lib/metaforce_spec.rb b/spec/lib/metaforce_spec.rb index 932046f..670d4fe 100644 --- a/spec/lib/metaforce_spec.rb +++ b/spec/lib/metaforce_spec.rb @@ -13,8 +13,8 @@ context 'when environment variables are not defined' do it 'proxies the login call' do - Metaforce::Login.should_receive(:new).with('foo', 'foobar', 'whizbang').and_call_original - Metaforce::Login.any_instance.should_receive(:login) + expect(Metaforce::Login).to receive(:new).with('foo', 'foobar', 'whizbang').and_call_original + expect_any_instance_of(Metaforce::Login).to receive(:login) described_class.login args end end @@ -33,8 +33,8 @@ end it 'proxies the login call' do - Metaforce::Login.should_receive(:new).with('foo', 'foobar', 'whizbang').and_call_original - Metaforce::Login.any_instance.should_receive(:login) + expect(Metaforce::Login).to receive(:new).with('foo', 'foobar', 'whizbang').and_call_original + expect_any_instance_of(Metaforce::Login).to receive(:login) described_class.login end end diff --git a/spec/lib/reporters/base_reporter_spec.rb b/spec/lib/reporters/base_reporter_spec.rb index 814bb35..e83bd16 100644 --- a/spec/lib/reporters/base_reporter_spec.rb +++ b/spec/lib/reporters/base_reporter_spec.rb @@ -10,9 +10,9 @@ let(:problem) { Hashie::Mash.new(file_name: 'path/file', line_number: '10', problem: 'Foobar') } it 'prints the problem' do - reporter.should_receive(:say).with(' path/file:10', :red) - reporter.should_receive(:say).with(' Foobar') - reporter.should_receive(:say).with + expect(reporter).to receive(:say).with(' path/file:10', :red) + expect(reporter).to receive(:say).with(' Foobar') + expect(reporter).to receive(:say).with( no_args ) reporter.problem(problem) end end @@ -21,9 +21,9 @@ let(:problem) { Hashie::Mash.new(file_name: 'path/file', problem: 'Foobar') } it 'prints the problem' do - reporter.should_receive(:say).with(' path/file:', :red) - reporter.should_receive(:say).with(' Foobar') - reporter.should_receive(:say).with + expect(reporter).to receive(:say).with(' path/file:', :red) + expect(reporter).to receive(:say).with(' Foobar') + expect(reporter).to receive(:say).with( no_args ) reporter.problem(problem) end end @@ -32,8 +32,8 @@ describe '.report_problems' do context 'when there are no problems' do it 'does not report any problems' do - reporter.should_receive(:say).never - reporter.should_receive(:problem).never + expect(reporter).to receive(:say).never + expect(reporter).to receive(:problem).never reporter.report_problems end end @@ -42,10 +42,10 @@ let(:results) { Hashie::Mash.new(success: true, messages: { problem: 'Problem', file_name: 'path/file', line_number: '10' }) } it 'prints each problem' do - reporter.should_receive(:say) - reporter.should_receive(:say).with('Problems:', :red) - reporter.should_receive(:say) - reporter.should_receive(:problem) + expect(reporter).to receive(:say) + expect(reporter).to receive(:say).with('Problems:', :red) + expect(reporter).to receive(:say) + expect(reporter).to receive(:problem) reporter.report_problems end end @@ -55,12 +55,12 @@ subject { reporter.problems? } context 'when there are no problems' do - it { should be_false } + it { should be_falsey } end context 'when there are problems' do let(:results) { Hashie::Mash.new(success: true, messages: { problem: 'Problem', file_name: 'path/file', line_number: '10' }) } - it { should be_true } + it { should be_truthy } end end @@ -68,12 +68,12 @@ subject { reporter.issues? } context 'when there are no problems' do - it { should be_false } + it { should be_falsey } end context 'when there are problems' do let(:results) { Hashie::Mash.new(success: true, messages: { problem: 'Problem', file_name: 'path/file', line_number: '10' }) } - it { should be_true } + it { should be_truthy } end end end diff --git a/spec/lib/reporters/deploy_reporter_spec.rb b/spec/lib/reporters/deploy_reporter_spec.rb index 494ef15..0f4c00a 100644 --- a/spec/lib/reporters/deploy_reporter_spec.rb +++ b/spec/lib/reporters/deploy_reporter_spec.rb @@ -9,9 +9,9 @@ let(:failure) { Hashie::Mash.new(stack_trace: 'stack trace', message: 'message') } it 'prints the failure' do - reporter.should_receive(:say).with(' stack trace:', :red) - reporter.should_receive(:say).with(' message') - reporter.should_receive(:say).with + expect(reporter).to receive(:say).with(' stack trace:', :red) + expect(reporter).to receive(:say).with(' message') + expect(reporter).to receive(:say).with( no_args ) reporter.failed(failure) end end @@ -19,9 +19,9 @@ describe '.report' do context 'when the deploy was successfull' do it 'should report everything' do - reporter.should_receive(:report_problems) - reporter.should_receive(:report_failed_tests) - reporter.should_receive(:report_test_results) + expect(reporter).to receive(:report_problems) + expect(reporter).to receive(:report_failed_tests) + expect(reporter).to receive(:report_test_results) reporter.report end end @@ -30,9 +30,9 @@ let(:results) { Hashie::Mash.new(success: false) } it 'should report everything except test results' do - reporter.should_receive(:report_problems) - reporter.should_receive(:report_failed_tests) - reporter.should_receive(:report_test_results).never + expect(reporter).to receive(:report_problems) + expect(reporter).to receive(:report_failed_tests) + expect(reporter).to receive(:report_test_results).never reporter.report end end @@ -46,8 +46,8 @@ let(:num_failures) { '0' } it 'does not report any failed tests' do - reporter.should_receive(:say).never - reporter.should_receive(:failed).never + expect(reporter).to receive(:say).never + expect(reporter).to receive(:failed).never reporter.report_failed_tests end end @@ -58,10 +58,10 @@ let(:num_failures) { '1' } it 'prints each failed tests' do - reporter.should_receive(:say) - reporter.should_receive(:say).with('Failures:', :red) - reporter.should_receive(:say) - reporter.should_receive(:failed) + expect(reporter).to receive(:say) + expect(reporter).to receive(:say).with('Failures:', :red) + expect(reporter).to receive(:say) + expect(reporter).to receive(:failed) reporter.report_failed_tests end end @@ -71,10 +71,10 @@ let(:num_failures) { '2' } it 'prints each failed tests' do - reporter.should_receive(:say) - reporter.should_receive(:say).with('Failures:', :red) - reporter.should_receive(:say) - reporter.should_receive(:failed).twice + expect(reporter).to receive(:say) + expect(reporter).to receive(:say).with('Failures:', :red) + expect(reporter).to receive(:say) + expect(reporter).to receive(:failed).twice reporter.report_failed_tests end end @@ -88,9 +88,9 @@ let(:num_failures) { '5' } it 'prints the test results in red' do - reporter.should_receive(:say) - reporter.should_receive(:say).with("Finished in 20 seconds") - reporter.should_receive(:say).with("10 tests, 5 failures", :red) + expect(reporter).to receive(:say) + expect(reporter).to receive(:say).with("Finished in 20 seconds") + expect(reporter).to receive(:say).with("10 tests, 5 failures", :red) reporter.report_test_results end end @@ -99,9 +99,9 @@ let(:num_failures) { '0' } it 'prints the test results in red' do - reporter.should_receive(:say) - reporter.should_receive(:say).with("Finished in 20 seconds") - reporter.should_receive(:say).with("10 tests, 0 failures", :green) + expect(reporter).to receive(:say) + expect(reporter).to receive(:say).with("Finished in 20 seconds") + expect(reporter).to receive(:say).with("10 tests, 0 failures", :green) reporter.report_test_results end end @@ -113,12 +113,12 @@ context 'when there are failures' do let(:num_failures) { '5' } - it { should be_true } + it { should be_truthy } end context 'when there are no failures' do let(:num_failures) { '0' } - it { should be_false } + it { should be_falsey } end end end diff --git a/spec/lib/reporters/retrieve_reporter_spec.rb b/spec/lib/reporters/retrieve_reporter_spec.rb index 8af678c..9588fb5 100644 --- a/spec/lib/reporters/retrieve_reporter_spec.rb +++ b/spec/lib/reporters/retrieve_reporter_spec.rb @@ -7,7 +7,7 @@ describe '.report' do it 'reports the problems' do - reporter.should_receive(:report_problems) + expect(reporter).to receive(:report_problems) reporter.report end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a34a606..3811a90 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,6 +2,7 @@ Bundler.require :default, :development require 'pp' require 'rspec/mocks' +require 'rspec/its' Dir['./spec/support/**/*.rb'].sort.each {|f| require f} @@ -11,7 +12,7 @@ config.before(:each) do Metaforce.configuration.threading = false - Metaforce::Job.any_instance.stub(:sleep) + allow_any_instance_of(Metaforce::Job).to(receive(:sleep)) end end @@ -22,10 +23,10 @@ match do |configuration| @actual = configuration.send(option.to_sym) - @actual.should eq @value + expect(@actual).to eq @value end - failure_message_for_should do |configuration| + failure_message do |configuration| "Expected #{option} to be set to #{@value.inspect}, got #{@actual.inspect}" end end diff --git a/spec/support/client.rb b/spec/support/client.rb index 5a1b65e..4d8de26 100644 --- a/spec/support/client.rb +++ b/spec/support/client.rb @@ -3,13 +3,13 @@ let(:exception) { Savon::SOAP::Fault.new(HTTPI::Response.new(403, {}, '')) } before do - client.send(:client).should_receive(:request).once.and_raise(exception) - exception.stub(:message).and_return('INVALID_SESSION_ID') + expect(client.send(:client)).to receive(:request).once.and_raise(exception) + allow(exception).to receive(:message).and_return('INVALID_SESSION_ID') end context 'and no authentication handler is present' do before do - client.stub(:authentication_handler).and_return(nil) + allow(client).to receive(:authentication_handler).and_return(nil) end it 'raises the exception' do @@ -23,14 +23,14 @@ end before do - client.stub(:authentication_handler).and_return(handler) + allow(client).to receive(:authentication_handler).and_return(handler) end it 'calls the authentication handler and resends the request' do response = double('response') - response.stub(:body).and_return(Hashie::Mash.new(:foo_response => {:result => ''})) - client.send(:client).should_receive(:request).once.and_return(response) - handler.should_receive(:call).and_call_original + allow(response).to receive(:body).and_return(Hashie::Mash.new(:foo_response => {:result => ''})) + expect(client.send(:client)).to receive(:request).once.and_return(response) + expect(handler).to receive(:call).and_call_original client.send(:request, :foo) expect(client.send(:client).config.soap_header).to eq("ins0:SessionHeader"=>{"ins0:sessionId"=>"foo"}) end