spec/lib/appsignal/capistrano2_spec.rb in appsignal-1.1.1 vs spec/lib/appsignal/capistrano2_spec.rb in appsignal-1.1.2

- old
+ new

@@ -4,12 +4,21 @@ require 'capistrano' require 'capistrano/configuration' require 'appsignal/capistrano' describe "Capistrano 2 integration" do + let(:out_stream) { StringIO.new } let(:config) { project_fixture_config } + before do + @original_stdout = $stdout + $stdout = out_stream + end + after do + $stdout = @original_stdout + end + before :all do @capistrano_config = Capistrano::Configuration.new Appsignal::Capistrano.tasks(@capistrano_config) end @@ -37,11 +46,11 @@ it "should be instantiated with the right params" do Appsignal::Config.should_receive(:new).with( project_fixture_path, 'production', {}, - kind_of(Capistrano::Logger) + kind_of(Logger) ) end context "when appsignal_config is available" do before do @@ -51,11 +60,11 @@ it "should be instantiated with the right params" do Appsignal::Config.should_receive(:new).with( project_fixture_path, 'production', {:name => 'AppName'}, - kind_of(Capistrano::Logger) + kind_of(Logger) ) end context "when rack_env is used instead of rails_env" do before do @@ -66,27 +75,20 @@ it "should be instantiated with the right params" do Appsignal::Config.should_receive(:new).with( project_fixture_path, 'rack_production', {:name => 'AppName'}, - kind_of(Capistrano::Logger) + kind_of(Logger) ) end end end after { @capistrano_config.find_and_execute_task('appsignal:deploy') } end context "send marker" do - before :all do - @io = StringIO.new - @logger = Capistrano::Logger.new(:output => @io) - @logger.level = Capistrano::Logger::MAX_LEVEL - @capistrano_config.logger = @logger - end - let(:marker_data) do { :revision => '503ce0923ed177a3ce000005', :user => 'batman' } @@ -94,12 +96,11 @@ context "when active for this environment" do before do @marker = Appsignal::Marker.new( marker_data, - config, - @logger + config ) Appsignal::Marker.stub(:new => @marker) end context "proper setup" do @@ -109,22 +110,21 @@ end it "should add the correct marker data" do Appsignal::Marker.should_receive(:new).with( marker_data, - kind_of(Appsignal::Config), - kind_of(Capistrano::Logger) + kind_of(Appsignal::Config) ).and_return(@marker) @capistrano_config.find_and_execute_task('appsignal:deploy') end it "should transmit data" do @transmitter.should_receive(:transmit).and_return('200') @capistrano_config.find_and_execute_task('appsignal:deploy') - @io.string.should include('Notifying Appsignal of deploy with: revision: 503ce0923ed177a3ce000005, user: batman') - @io.string.should include('Appsignal has been notified of this deploy!') + out_stream.string.should include('Notifying Appsignal of deploy with: revision: 503ce0923ed177a3ce000005, user: batman') + out_stream.string.should include('Appsignal has been notified of this deploy!') end context "with overridden revision" do before do @capistrano_config.set(:appsignal_revision, 'abc123') @@ -133,32 +133,31 @@ Appsignal::Marker.should_receive(:new).with( { :revision => 'abc123', :user => 'batman' }, - kind_of(Appsignal::Config), - kind_of(Capistrano::Logger) + kind_of(Appsignal::Config) ).and_return(@marker) @capistrano_config.find_and_execute_task('appsignal:deploy') end end end it "should not transmit data" do @capistrano_config.find_and_execute_task('appsignal:deploy') - @io.string.should include('Notifying Appsignal of deploy with: revision: 503ce0923ed177a3ce000005, user: batman') - @io.string.should include('Something went wrong while trying to notify Appsignal:') + out_stream.string.should include('Notifying Appsignal of deploy with: revision: 503ce0923ed177a3ce000005, user: batman') + out_stream.string.should include('Something went wrong while trying to notify Appsignal:') end context "dry run" do before { @capistrano_config.dry_run = true } it "should not send deploy marker" do @marker.should_not_receive(:transmit) @capistrano_config.find_and_execute_task('appsignal:deploy') - @io.string.should include('Dry run: Deploy marker not actually sent.') + out_stream.string.should include('Dry run: AppSignal deploy marker not actually sent.') end end end context "when not active for this environment" do @@ -167,16 +166,10 @@ end it "should not send deploy marker" do Appsignal::Marker.should_not_receive(:new) @capistrano_config.find_and_execute_task('appsignal:deploy') - @io.string.encode( - 'UTF-8', - 'binary', - :invalid => :replace, - :undef => :replace, - :replace => '' - ).should include("config for 'nonsense' not found") + out_stream.string.should include('Not notifying of deploy, config is not active') end end end end end