spec/lib/appsignal/capistrano3_spec.rb in appsignal-2.0.3 vs spec/lib/appsignal/capistrano3_spec.rb in appsignal-2.0.4
- old
+ new
@@ -5,11 +5,12 @@
include Capistrano::DSL
describe "Capistrano 3 integration" do
let(:config) { project_fixture_config }
- let(:out_stream) { StringIO.new }
+ let(:out_stream) { std_stream }
+ let(:output) { out_stream.read }
let(:logger) { Logger.new(out_stream) }
let!(:capistrano_config) do
Capistrano::Configuration.reset!
Capistrano::Configuration.env.tap do |c|
c.set(:log_level, :error)
@@ -19,16 +20,17 @@
c.set(:deploy_to, '/home/username/app')
c.set(:current_release, '')
c.set(:current_revision, '503ce0923ed177a3ce000005')
end
end
- before do
- Rake::Task['appsignal:deploy'].reenable
+ before { Rake::Task['appsignal:deploy'].reenable }
+
+ def run
+ capture_std_streams(out_stream, out_stream) do
+ invoke('appsignal:deploy')
+ end
end
- around do |example|
- capture_std_streams(out_stream, out_stream) { example.run }
- end
it "should have a deploy task" do
Rake::Task.task_defined?('appsignal:deploy').should be_true
end
@@ -110,13 +112,11 @@
)
end
end
end
- after do
- invoke('appsignal:deploy')
- end
+ after { run }
end
describe "markers" do
def stub_marker_request(data = {})
stub_api_request config, 'markers', marker_data.merge(data)
@@ -130,39 +130,38 @@
end
context "when active for this environment" do
it "transmits marker" do
stub_marker_request.to_return(:status => 200)
- invoke('appsignal:deploy')
+ run
- expect(out_stream.string).to include \
+ expect(output).to include \
'Notifying AppSignal of deploy with: revision: 503ce0923ed177a3ce000005, user: batman',
'AppSignal has been notified of this deploy!'
end
context "with overridden revision" do
before do
capistrano_config.set(:appsignal_revision, 'abc123')
stub_marker_request(:revision => 'abc123').to_return(:status => 200)
- invoke('appsignal:deploy')
+ run
end
it "transmits the overriden revision" do
- expect(out_stream.string).to include \
+ expect(output).to include \
'Notifying AppSignal of deploy with: revision: abc123, user: batman',
'AppSignal has been notified of this deploy!'
end
end
context "with failed request" do
before do
stub_marker_request.to_return(:status => 500)
- invoke('appsignal:deploy')
+ run
end
it "does not transmit marker" do
- output = out_stream.string
expect(output).to include \
'Notifying AppSignal of deploy with: revision: 503ce0923ed177a3ce000005, user: batman',
'Something went wrong while trying to notify AppSignal:'
expect(output).to_not include 'AppSignal has been notified of this deploy!'
end
@@ -170,14 +169,14 @@
end
context "when not active for this environment" do
before do
capistrano_config.set(:rails_env, 'nonsense')
- invoke('appsignal:deploy')
+ run
end
it "should not send deploy marker" do
- expect(out_stream.string).to include \
+ expect(output).to include \
"Not notifying of deploy, config is not active for environment: nonsense"
end
end
end
end