appsignal 2.0.3 → 2.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,495 +1,629 @@
1
- require 'appsignal/cli'
1
+ require "appsignal/cli"
2
2
 
3
3
  describe Appsignal::CLI::Install do
4
- let(:out_stream) { StringIO.new }
5
- let(:cli) { Appsignal::CLI::Install }
6
- let(:config) { Appsignal::Config.new(nil, {}) }
7
- let(:auth_check) { double }
8
-
4
+ include CLIHelpers
5
+
6
+ let(:out_stream) { std_stream }
7
+ let(:output) { out_stream.read }
8
+ let(:push_api_key) { "my_key" }
9
+ let(:config) { Appsignal::Config.new(tmp_dir, "") }
10
+ let(:config_file_path) { File.join(tmp_dir, "config", "appsignal.yml") }
11
+ let(:config_file) { File.read(config_file_path) }
9
12
  before do
10
- Dir.stub(:pwd => project_fixture_path)
11
- Appsignal::AuthCheck.stub(:new => auth_check)
12
- auth_check.stub(:perform => '200')
13
- cli.stub(:sleep)
14
- cli.stub(:press_any_key)
13
+ stub_api_validation_request
14
+ # Stub calls to speed up tests
15
+ allow(described_class).to receive(:sleep)
16
+ allow(described_class).to receive(:press_any_key)
17
+ allow(Appsignal::Demo).to receive(:transmit).and_return(true)
15
18
  end
16
19
  around do |example|
17
- capture_stdout(out_stream) { example.run }
20
+ original_stdin = $stdin
21
+ $stdin = StringIO.new
22
+ example.run
23
+ $stdin = original_stdin
18
24
  end
19
25
 
20
- describe ".run" do
21
- it "should not continue if there is no key" do
22
- cli.run(nil, config)
26
+ define :include_complete_install do
27
+ match do |actual|
28
+ actual.include?("AppSignal installation complete")
29
+ end
30
+ end
23
31
 
24
- out_stream.string.should include('Problem encountered:')
25
- out_stream.string.should include('No push API key entered')
32
+ define :include_env_push_api_key do |key|
33
+ match do |actual|
34
+ actual.include?("export APPSIGNAL_PUSH_API_KEY=#{key}")
26
35
  end
36
+ end
37
+ define :include_env_app_name do |name|
38
+ match do |actual|
39
+ actual.include?("export APPSIGNAL_APP_NAME=#{name}")
40
+ end
41
+ end
27
42
 
28
- context "auth check" do
29
- it "should exit if the key is invalid" do
30
- auth_check.stub(:perform => '402')
43
+ define :configure_app_name do |name|
44
+ match do |file_contents|
45
+ file_contents =~ /^ name: "#{name}"/
46
+ end
47
+ end
48
+ define :configure_push_api_key do |key|
49
+ match do |file_contents|
50
+ file_contents =~ /^ push_api_key: "#{key}"/
51
+ end
52
+ end
53
+ define :configure_environment do |env|
54
+ match do |file_contents|
55
+ file_contents =~ /^#{env}:$/
56
+ end
57
+ end
58
+ define :include_file_config do
59
+ match do |log|
60
+ log.include?("Config file written to config/appsignal.yml")
61
+ end
62
+ end
63
+
64
+ define :include_demo_transmission do
65
+ match do |log|
66
+ log.include?("Sending example data to AppSignal") &&
67
+ log.include?("Example data sent!")
68
+ end
69
+ end
31
70
 
32
- cli.run('key', config)
71
+ def stub_api_validation_request
72
+ config[:push_api_key] = push_api_key
73
+ stub_api_request config, "auth"
74
+ end
33
75
 
34
- out_stream.string.should include("API key 'key' is not valid")
35
- end
76
+ alias_method :enter_app_name, :set_input
36
77
 
37
- it "should exit if there was an error" do
38
- auth_check.stub(:perform).and_raise(StandardError.new)
78
+ def choose_config_file
79
+ set_input "1"
80
+ end
39
81
 
40
- cli.run('key', config)
82
+ def choose_environment_config
83
+ set_input "2"
84
+ end
41
85
 
42
- out_stream.string.should include("There was an error validating your API key")
86
+ def run
87
+ Dir.chdir tmp_dir do
88
+ prepare_input
89
+ capture_stdout(out_stream) do
90
+ run_cli(["install", push_api_key])
43
91
  end
44
92
  end
45
93
  end
46
94
 
47
- context "with rails" do
48
- if rails_present?
49
- describe ".run" do
50
- it "should install with environment variables" do
51
- cli.should_receive(:gets).once.and_return('n')
52
- cli.should_receive(:gets).once.and_return('2')
95
+ shared_examples "push_api_key validation" do
96
+ context "without key" do
97
+ let(:push_api_key) {}
53
98
 
54
- cli.run('key', config)
99
+ it "does not install" do
100
+ run
55
101
 
56
- out_stream.string.should include("Validating API key...")
57
- out_stream.string.should include("API key valid")
58
- out_stream.string.should include("Installing for Ruby on Rails")
59
- out_stream.string.should include("export APPSIGNAL_PUSH_API_KEY=key")
60
- out_stream.string.should include("AppSignal installation complete")
61
- end
62
-
63
- it "should install with config file" do
64
- cli.should_receive(:gets).once.and_return('n')
65
- cli.should_receive(:gets).once.and_return('1')
66
- cli.should_receive(:write_config_file)
67
-
68
- cli.run('key', config)
102
+ expect(output).to include "Problem encountered:",
103
+ "No push API key entered"
104
+ end
105
+ end
69
106
 
70
- out_stream.string.should include("Validating API key...")
71
- out_stream.string.should include("API key valid")
72
- out_stream.string.should include("Installing for Ruby on Rails")
73
- out_stream.string.should include("AppSignal installation complete")
74
- end
107
+ context "with key" do
108
+ let(:push_api_key) { "my_key" }
75
109
 
76
- it "should install with an overridden app name and environment variables" do
77
- cli.should_receive(:gets).once.and_return('y')
78
- cli.should_receive(:gets).once.and_return('Appname')
79
- cli.should_receive(:gets).once.and_return('2')
110
+ context "when the key is valid" do
111
+ before { stub_api_validation_request.to_return(:status => 200) }
80
112
 
81
- cli.run('key', config)
113
+ it "continues with the installer" do
114
+ enter_app_name "Test App"
115
+ choose_environment_config
116
+ run
82
117
 
83
- out_stream.string.should include("Validating API key...")
84
- out_stream.string.should include("API key valid")
85
- out_stream.string.should include("Installing for Ruby on Rails")
86
- out_stream.string.should include("export APPSIGNAL_PUSH_API_KEY=key")
87
- out_stream.string.should include("export APPSIGNAL_APP_NAME=Appname")
88
- out_stream.string.should include("AppSignal installation complete")
118
+ expect(output).to include("Validating API key...", "API key valid")
89
119
  end
120
+ end
90
121
 
91
- it "should install with an overridden app name and a config file" do
92
- cli.should_receive(:gets).once.and_return('y')
93
- cli.should_receive(:gets).once.and_return('Appname')
94
- cli.should_receive(:gets).once.and_return('1')
95
- cli.should_receive(:write_config_file)
96
-
97
- cli.run('key', config)
122
+ context "when the key is invalid" do
123
+ before { stub_api_validation_request.to_return(:status => 402) }
98
124
 
99
- out_stream.string.should include("Validating API key...")
100
- out_stream.string.should include("API key valid")
101
- out_stream.string.should include("Installing for Ruby on Rails")
102
- out_stream.string.should include("AppSignal installation complete")
125
+ it "prints an error" do
126
+ run
127
+ expect(output).to include "API key 'my_key' is not valid"
103
128
  end
104
129
  end
105
130
 
106
- describe ".rails_environments" do
131
+ context "when there is an error validating" do
107
132
  before do
108
- Dir.stub(:pwd => project_fixture_path)
133
+ expect(Appsignal::AuthCheck).to receive(:new).and_raise(StandardError)
109
134
  end
110
135
 
111
- subject { cli.rails_environments }
112
-
113
- it { should eq ['development', 'production'] }
136
+ it "prints an error" do
137
+ run
138
+ expect(output).to include "There was an error validating your API key"
139
+ end
114
140
  end
141
+ end
142
+ end
115
143
 
116
- describe ".installed_frameworks" do
117
- subject { cli.installed_frameworks }
144
+ shared_examples "requires an application name" do
145
+ before do
146
+ enter_app_name ""
147
+ enter_app_name "Test app"
148
+ choose_environment_config
149
+ run
150
+ end
118
151
 
119
- it { should include(:rails) }
120
- end
152
+ it "requires an application name" do
153
+ expect(output.scan(/Enter application name:/).length).to eq(2)
121
154
  end
122
155
  end
123
156
 
124
- context "with sinatra" do
125
- if sinatra_present? && !padrino_present? && !rails_present?
126
- describe ".install" do
127
- it "should install with environment variables" do
128
- cli.should_receive(:gets).once.and_return('Appname')
129
- cli.should_receive(:gets).once.and_return('2')
157
+ shared_examples "capistrano install" do
158
+ let(:capfile) { File.join(tmp_dir, "Capfile") }
159
+ before do
160
+ FileUtils.mkdir_p(tmp_dir)
130
161
 
131
- cli.run('key', config)
162
+ enter_app_name "foo"
163
+ set_input "n"
164
+ choose_environment_config
165
+ end
166
+ after do
167
+ FileUtils.rm_rf(tmp_dir)
168
+ FileUtils.mkdir_p(tmp_dir)
169
+ end
132
170
 
133
- out_stream.string.should include("Validating API key...")
134
- out_stream.string.should include("API key valid")
135
- out_stream.string.should include("Installing for Sinatra")
136
- out_stream.string.should include("export APPSIGNAL_PUSH_API_KEY=key")
137
- out_stream.string.should include("AppSignal installation complete")
138
- end
171
+ context "without Capfile" do
172
+ it "does nothing" do
173
+ run
139
174
 
140
- it "should install with a config file" do
141
- cli.should_receive(:gets).once.and_return('Appname')
142
- cli.should_receive(:gets).once.and_return('1')
143
- cli.should_receive(:write_config_file)
175
+ expect(output).to_not include "Adding AppSignal integration to Capfile"
176
+ expect(File.exist?(capfile)).to be_false
177
+ end
178
+ end
144
179
 
145
- cli.run('key', config)
180
+ context "with Capfile" do
181
+ context "when already installed" do
182
+ before { File.open(capfile, "w") { |f| f.write("require 'appsignal/capistrano'") } }
146
183
 
147
- out_stream.string.should include("Validating API key...")
148
- out_stream.string.should include("API key valid")
149
- out_stream.string.should include("Installing for Sinatra")
150
- out_stream.string.should include("AppSignal installation complete")
184
+ it "does not add another require to Capfile" do
185
+ run
186
+
187
+ expect(output).to_not include "Adding AppSignal integration to Capfile"
188
+ expect(File.read(capfile).scan(/appsignal/).count).to eq(1)
151
189
  end
152
190
  end
153
191
 
154
- describe ".installed_frameworks" do
155
- subject { cli.installed_frameworks }
192
+ context "when not installed" do
193
+ before { FileUtils.touch(capfile) }
194
+
195
+ it "adds a require to Capfile" do
196
+ run
156
197
 
157
- it { should include(:sinatra) }
198
+ expect(output).to include "Adding AppSignal integration to Capfile"
199
+ expect(File.read(capfile)).to include "require 'appsignal/capistrano'"
200
+ end
158
201
  end
159
202
  end
160
203
  end
161
204
 
162
- context "with padrino" do
163
- if padrino_present?
164
- describe ".install" do
165
- it "should install with environment variables" do
166
- cli.should_receive(:gets).once.and_return('Appname')
167
- cli.should_receive(:gets).once.and_return('2')
168
-
169
- cli.run('key', config)
170
-
171
- out_stream.string.should include("Validating API key...")
172
- out_stream.string.should include("API key valid")
173
- out_stream.string.should include("Installing for Padrino")
174
- out_stream.string.should include("export APPSIGNAL_PUSH_API_KEY=key")
175
- out_stream.string.should include("AppSignal installation complete")
176
- end
205
+ shared_examples "windows installation" do
206
+ before do
207
+ allow(Gem).to receive(:win_platform?).and_return(true)
208
+ expect(Appsignal::Demo).to_not receive(:transmit)
209
+ run
210
+ end
177
211
 
178
- it "should install with a config file" do
179
- cli.should_receive(:gets).once.and_return('Appname')
180
- cli.should_receive(:gets).once.and_return('1')
181
- cli.should_receive(:write_config_file)
212
+ it "prints a warning for windows" do
213
+ expect(output).to include("The AppSignal agent currently does not work on Windows")
214
+ expect(output).to include("test/staging/production environment")
215
+ end
216
+ end
182
217
 
183
- cli.run('key', config)
218
+ shared_examples "demo data" do
219
+ context "with demo data sent" do
220
+ before do
221
+ expect(Appsignal::Demo).to receive(:transmit).and_return(true)
222
+ run
223
+ end
184
224
 
185
- out_stream.string.should include("Validating API key...")
186
- out_stream.string.should include("API key valid")
187
- out_stream.string.should include("Installing for Padrino")
188
- out_stream.string.should include("AppSignal installation complete")
189
- end
225
+ it "prints sending demo data" do
226
+ expect(output).to include "Sending example data to AppSignal", "Example data sent!"
190
227
  end
228
+ end
191
229
 
192
- describe ".installed_frameworks" do
193
- subject { cli.installed_frameworks }
230
+ context "without demo data being sent" do
231
+ before do
232
+ expect(Appsignal::Demo).to receive(:transmit).and_return(false)
233
+ run
234
+ end
194
235
 
195
- it { should include(:padrino) }
236
+ it "prints that it couldn't send the demo data" do
237
+ expect(output).to include "Sending example data to AppSignal",
238
+ "Couldn't start the AppSignal agent and send example data",
239
+ "`appsignal diagnose`"
196
240
  end
197
241
  end
198
242
  end
199
243
 
200
- context "with grape" do
201
- if grape_present?
202
- describe ".install" do
203
- it "should install with environment variables" do
204
- cli.should_receive(:gets).once.and_return('Appname')
205
- cli.should_receive(:gets).once.and_return('2')
206
-
207
- cli.run('key', config)
244
+ if rails_present?
245
+ context "with rails" do
246
+ let(:installation_instructions) { ["Installing for Ruby on Rails"] }
247
+ let(:app_name) { "MyApp" }
248
+ let(:config_dir) { File.join(tmp_dir, "config") }
249
+ let(:environments_dir) { File.join(config_dir, "environments") }
250
+ before do
251
+ # Fake Rails directory
252
+ FileUtils.mkdir_p(config_dir)
253
+ FileUtils.mkdir_p(environments_dir)
254
+ FileUtils.touch(File.join(config_dir, "application.rb"))
255
+ FileUtils.touch(File.join(environments_dir, "development.rb"))
256
+ FileUtils.touch(File.join(environments_dir, "staging.rb"))
257
+ FileUtils.touch(File.join(environments_dir, "production.rb"))
258
+ enter_app_name app_name
259
+ end
208
260
 
209
- out_stream.string.should include("Validating API key...")
210
- out_stream.string.should include("API key valid")
211
- out_stream.string.should include("Installing for Grape")
212
- out_stream.string.should include("export APPSIGNAL_PUSH_API_KEY=key")
213
- out_stream.string.should include("AppSignal installation complete")
261
+ describe "environments" do
262
+ before do
263
+ File.delete(File.join(environments_dir, "development.rb"))
264
+ File.delete(File.join(environments_dir, "staging.rb"))
265
+ set_input "n"
266
+ choose_config_file
214
267
  end
215
268
 
216
- it "should install with a config file" do
217
- cli.should_receive(:gets).once.and_return('Appname')
218
- cli.should_receive(:gets).once.and_return('1')
219
- cli.should_receive(:write_config_file)
269
+ it "only configures the available environments" do
270
+ run
220
271
 
221
- cli.run('key', config)
272
+ expect(output).to include_file_config
273
+ expect(config_file).to configure_app_name(app_name)
274
+ expect(config_file).to configure_push_api_key(push_api_key)
275
+ expect(config_file).to_not configure_environment("development")
276
+ expect(config_file).to_not configure_environment("staging")
277
+ expect(config_file).to configure_environment("production")
222
278
 
223
- out_stream.string.should include("Validating API key...")
224
- out_stream.string.should include("API key valid")
225
- out_stream.string.should include("Installing for Grape")
226
- out_stream.string.should include("AppSignal installation complete")
279
+ expect(output).to include(*installation_instructions)
280
+ expect(output).to include_complete_install
281
+ expect(output).to include_demo_transmission
227
282
  end
228
283
  end
229
284
 
230
- describe ".installed_frameworks" do
231
- subject { cli.installed_frameworks }
285
+ context "without custom name" do
286
+ before { set_input "n" }
232
287
 
233
- it { should include(:grape) }
234
- end
235
- end
236
- end
288
+ it_behaves_like "push_api_key validation"
289
+
290
+ context "with configuration using environment variables" do
291
+ before { choose_environment_config }
292
+
293
+ it_behaves_like "windows installation"
294
+ it_behaves_like "capistrano install"
295
+ it_behaves_like "demo data"
296
+
297
+ it "prints environment variables" do
298
+ run
237
299
 
238
- context "with unknown framework" do
239
- if !rails_present? && !sinatra_present? && !padrino_present? && !grape_present?
240
- describe ".install" do
241
- it "should give a message about unknown framework" do
242
- cli.run('key', config)
300
+ expect(output).to include_env_push_api_key(push_api_key)
301
+ expect(output).to_not include_env_app_name
302
+ end
303
+
304
+ it "completes the installation" do
305
+ run
243
306
 
244
- out_stream.string.should include("Validating API key...")
245
- out_stream.string.should include("API key valid")
246
- out_stream.string.should include("We could not detect which framework you are using.")
307
+ expect(output).to include(*installation_instructions)
308
+ expect(output).to include_complete_install
309
+ end
247
310
  end
248
- end
249
311
 
250
- describe ".installed_frameworks" do
251
- subject { cli.installed_frameworks }
312
+ context "with configuration using a configuration file" do
313
+ before { choose_config_file }
252
314
 
253
- it { should be_empty }
254
- end
255
- end
256
- end
315
+ it_behaves_like "windows installation"
316
+ it_behaves_like "capistrano install"
317
+ it_behaves_like "demo data"
257
318
 
258
- describe ".colorize" do
259
- subject { cli.colorize('text', :green) }
319
+ it "writes configuration to file" do
320
+ run
260
321
 
261
- context "on windows" do
262
- before do
263
- Gem.stub(:win_platform? => true)
264
- end
322
+ expect(output).to include_file_config
323
+ expect(config_file).to configure_app_name(app_name)
324
+ expect(config_file).to configure_push_api_key(push_api_key)
325
+ expect(config_file).to configure_environment("development")
326
+ expect(config_file).to configure_environment("staging")
327
+ expect(config_file).to configure_environment("production")
328
+ end
265
329
 
266
- it { should eq 'text' }
267
- end
330
+ it "completes the installation" do
331
+ run
268
332
 
269
- context "not on windows" do
270
- before do
271
- Gem.stub(:win_platform? => false)
333
+ expect(output).to include(*installation_instructions)
334
+ expect(output).to include_complete_install
335
+ end
336
+ end
272
337
  end
273
338
 
274
- it { should eq "\e[32mtext\e[0m" }
275
- end
276
- end
339
+ context "with custom name" do
340
+ let(:app_name) { "Custom name" }
341
+ before { set_input "y" }
277
342
 
278
- describe ".periods" do
279
- it "should output three periods" do
280
- cli.periods
281
- out_stream.string.should include('...')
282
- end
283
- end
343
+ it_behaves_like "push_api_key validation"
284
344
 
285
- describe ".press_any_key" do
286
- before do
287
- cli.unstub(:press_any_key)
288
- STDIN.stub(:getch)
289
- end
345
+ it "requires the custom name" do
346
+ enter_app_name ""
347
+ enter_app_name app_name
348
+ choose_environment_config
349
+ run
290
350
 
291
- it "should continue" do
292
- cli.press_any_key
293
- out_stream.string.should include('Press any key')
294
- end
295
- end
351
+ expect(output.scan(/Choose app's display name:/).length).to eq(2)
352
+ end
296
353
 
297
- describe ".yes_or_no" do
298
- it "should take yes for an answer" do
299
- cli.should_receive(:gets).once.and_return('')
300
- cli.should_receive(:gets).once.and_return('nonsense')
301
- cli.should_receive(:gets).once.and_return('y')
354
+ context "with configuration using environment variables" do
355
+ before do
356
+ enter_app_name app_name
357
+ choose_environment_config
358
+ end
302
359
 
303
- cli.yes_or_no('yes or no?: ').should be_true
304
- end
360
+ it_behaves_like "windows installation"
361
+ it_behaves_like "capistrano install"
362
+ it_behaves_like "demo data"
305
363
 
306
- it "should take no for an answer" do
307
- cli.should_receive(:gets).once.and_return('')
308
- cli.should_receive(:gets).once.and_return('nonsense')
309
- cli.should_receive(:gets).once.and_return('n')
364
+ it "prints environment variables" do
365
+ run
310
366
 
311
- cli.yes_or_no('yes or no?: ').should be_false
312
- end
313
- end
367
+ expect(output).to include_env_push_api_key(push_api_key)
368
+ expect(output).to include_env_app_name(app_name)
369
+ end
370
+
371
+ it "completes the installation" do
372
+ run
373
+
374
+ expect(output).to include(*installation_instructions)
375
+ expect(output).to include_complete_install
376
+ end
377
+ end
378
+
379
+ context "with configuration using a configuration file" do
380
+ before do
381
+ enter_app_name app_name
382
+ choose_config_file
383
+ end
314
384
 
315
- describe ".required_input" do
316
- it "should collect required input" do
317
- cli.should_receive(:gets).once.and_return('')
318
- cli.should_receive(:gets).once.and_return('value')
385
+ it_behaves_like "windows installation"
386
+ it_behaves_like "capistrano install"
387
+ it_behaves_like "demo data"
319
388
 
320
- cli.required_input('provide: ').should eq 'value'
389
+ it "writes configuration to file" do
390
+ run
391
+
392
+ expect(output).to include_file_config
393
+ expect(config_file).to configure_app_name(app_name)
394
+ expect(config_file).to configure_push_api_key(push_api_key)
395
+ expect(config_file).to configure_environment("development")
396
+ expect(config_file).to configure_environment("staging")
397
+ expect(config_file).to configure_environment("production")
398
+ end
399
+
400
+ it "completes the installation" do
401
+ run
402
+
403
+ expect(output).to include(*installation_instructions)
404
+ expect(output).to include_complete_install
405
+ end
406
+ end
407
+ end
321
408
  end
322
409
  end
323
410
 
324
- describe ".configure" do
325
- before do
326
- config[:push_api_key] = 'key'
327
- config[:name] = 'Appname'
328
- end
411
+ if sinatra_present? && !padrino_present? && !rails_present?
412
+ context "with sinatra" do
413
+ it_behaves_like "push_api_key validation"
414
+ it_behaves_like "requires an application name"
415
+
416
+ describe "sinatra specific tests" do
417
+ let(:installation_instructions) do
418
+ [
419
+ "Installing for Sinatra",
420
+ "Sinatra requires some manual configuration.",
421
+ "require 'appsignal/integrations/sinatra'",
422
+ "http://docs.appsignal.com/getting-started/supported-frameworks.html#sinatra"
423
+ ]
424
+ end
425
+ let(:app_name) { "Test app" }
426
+ before { enter_app_name app_name }
329
427
 
330
- context "environment variables" do
331
- it "should output the environment variables" do
332
- cli.should_receive(:gets).once.and_return('2')
428
+ describe "configuration with environment variables" do
429
+ before { choose_environment_config }
333
430
 
334
- cli.configure(config, [], false)
431
+ it_behaves_like "windows installation"
432
+ it_behaves_like "capistrano install"
433
+ it_behaves_like "demo data"
335
434
 
336
- out_stream.string.should include("Add the following environment variables to configure AppSignal")
337
- out_stream.string.should include("export APPSIGNAL_ACTIVE=true")
338
- out_stream.string.should include("export APPSIGNAL_PUSH_API_KEY=key")
339
- end
435
+ it "prints environment variables" do
436
+ run
340
437
 
341
- it "should output the environment variables with name overwritten" do
342
- cli.should_receive(:gets).once.and_return('2')
438
+ expect(output).to include_env_push_api_key(push_api_key)
439
+ expect(output).to include_env_app_name(app_name)
440
+ end
343
441
 
344
- cli.configure(config, [], true)
442
+ it "completes the installation" do
443
+ run
345
444
 
346
- out_stream.string.should include("Add the following environment variables to configure AppSignal")
347
- out_stream.string.should include("export APPSIGNAL_ACTIVE=true")
348
- out_stream.string.should include("export APPSIGNAL_PUSH_API_KEY=key")
349
- out_stream.string.should include("export APPSIGNAL_APP_NAME=Appname")
350
- end
351
- end
445
+ expect(output).to include(*installation_instructions)
446
+ expect(output).to include_complete_install
447
+ end
448
+ end
449
+
450
+ describe "configure with a configuration file" do
451
+ before { choose_config_file }
352
452
 
353
- context "config file" do
354
- it "should write the config file" do
355
- cli.should_receive(:gets).once.and_return('1')
453
+ it_behaves_like "windows installation"
454
+ it_behaves_like "capistrano install"
455
+ it_behaves_like "demo data"
356
456
 
357
- cli.should_receive(:write_config_file).with(
358
- :push_api_key => 'key',
359
- :app_name => config[:name],
360
- :environments => []
361
- )
457
+ it "writes configuration to file" do
458
+ run
362
459
 
363
- cli.configure(config, [], false)
460
+ expect(output).to include_file_config
461
+ expect(config_file).to configure_app_name(app_name)
462
+ expect(config_file).to configure_push_api_key(push_api_key)
463
+ expect(config_file).to configure_environment("development")
464
+ expect(config_file).to configure_environment("staging")
465
+ expect(config_file).to configure_environment("production")
466
+ end
364
467
 
365
- out_stream.string.should include("Writing config file")
366
- out_stream.string.should include("Config file written to config/appsignal.yml")
468
+ it "completes the installation" do
469
+ run
470
+
471
+ expect(output).to include(*installation_instructions)
472
+ expect(output).to include_complete_install
473
+ end
474
+ end
367
475
  end
368
476
  end
477
+ end
369
478
 
370
- context "with capistrano" do
371
- let(:capfile) { File.join(tmp_dir, 'Capfile') }
372
- before do
373
- Dir.stub(:pwd => tmp_dir)
374
- FileUtils.mkdir_p(tmp_dir)
375
- cli.should_receive(:gets).once.and_return('2')
376
- end
377
- after do
378
- FileUtils.rm_rf(tmp_dir)
379
- end
479
+ if padrino_present?
480
+ context "with padrino" do
481
+ it_behaves_like "push_api_key validation"
482
+ it_behaves_like "requires an application name"
483
+
484
+ describe "padrino specific tests" do
485
+ let(:installation_instructions) do
486
+ [
487
+ "Installing for Padrino",
488
+ "Padrino requires some manual configuration.",
489
+ "http://docs.appsignal.com/getting-started/supported-frameworks.html#padrino"
490
+ ]
491
+ end
492
+ let(:app_name) { "Test app" }
493
+ before { enter_app_name app_name }
380
494
 
381
- context "without Capfile" do
382
- before { cli.configure(config, [], false) }
495
+ describe "configuration with environment variables" do
496
+ before { choose_environment_config }
383
497
 
384
- it "does nothing" do
385
- expect(out_stream.string).to_not include 'Adding AppSignal integration to Capfile'
386
- expect(File.exist?(capfile)).to be_false
387
- end
388
- end
498
+ it_behaves_like "windows installation"
499
+ it_behaves_like "capistrano install"
500
+ it_behaves_like "demo data"
389
501
 
390
- context "with Capfile" do
391
- context "when already installed" do
392
- before do
393
- File.open(capfile, 'w') { |f| f.write("require 'appsignal/capistrano'") }
394
- cli.configure(config, [], false)
502
+ it "prints environment variables" do
503
+ run
504
+
505
+ expect(output).to include_env_push_api_key(push_api_key)
506
+ expect(output).to include_env_app_name(app_name)
395
507
  end
396
508
 
397
- it "does not add another require to Capfile" do
398
- expect(out_stream.string).to_not include 'Adding AppSignal integration to Capfile'
399
- expect(File.read(capfile).scan(/appsignal/).count).to eq(1)
509
+ it "completes the installation" do
510
+ run
511
+
512
+ expect(output).to include(*installation_instructions)
513
+ expect(output).to include_complete_install
400
514
  end
401
515
  end
402
516
 
403
- context "when not installed" do
404
- before do
405
- FileUtils.touch(capfile)
406
- cli.configure(config, [], false)
517
+ describe "configure with a configuration file" do
518
+ before { choose_config_file }
519
+
520
+ it_behaves_like "windows installation"
521
+ it_behaves_like "capistrano install"
522
+ it_behaves_like "demo data"
523
+
524
+ it "writes configuration to file" do
525
+ run
526
+
527
+ expect(output).to include_file_config
528
+ expect(config_file).to configure_app_name(app_name)
529
+ expect(config_file).to configure_push_api_key(push_api_key)
530
+ expect(config_file).to configure_environment("development")
531
+ expect(config_file).to configure_environment("staging")
532
+ expect(config_file).to configure_environment("production")
407
533
  end
408
534
 
409
- it "adds a require to Capfile" do
410
- expect(out_stream.string).to include 'Adding AppSignal integration to Capfile'
411
- expect(File.read(capfile)).to include "require 'appsignal/capistrano'"
535
+ it "completes the installation" do
536
+ run
537
+
538
+ expect(output).to include(*installation_instructions)
539
+ expect(output).to include_complete_install
412
540
  end
413
541
  end
414
542
  end
415
543
  end
416
544
  end
417
545
 
418
- describe ".done_notice" do
419
- subject { out_stream.string }
546
+ if grape_present?
547
+ context "with grape" do
548
+ it_behaves_like "push_api_key validation"
549
+ it_behaves_like "requires an application name"
550
+
551
+ describe "grape specific tests" do
552
+ let(:installation_instructions) do
553
+ [
554
+ "Installing for Grape",
555
+ "Manual Grape configuration needed",
556
+ "http://docs.appsignal.com/getting-started/supported-frameworks.html#grape"
557
+ ]
558
+ end
559
+ let(:app_name) { "Test app" }
560
+ before { enter_app_name app_name }
420
561
 
421
- context "on windows" do
422
- before do
423
- Gem.stub(:win_platform? => true)
424
- cli.done_notice
425
- end
562
+ describe "configuration with environment variables" do
563
+ before { choose_environment_config }
426
564
 
427
- it { should include('The AppSignal agent currently does not work on Windows') }
428
- it { should include('test/staging/production environment') }
429
- end
565
+ it_behaves_like "windows installation"
566
+ it_behaves_like "capistrano install"
567
+ it_behaves_like "demo data"
430
568
 
431
- context "not on windows" do
432
- before { Gem.stub(:win_platform? => false) }
569
+ it "prints environment variables" do
570
+ run
433
571
 
434
- context "with demo data sent" do
435
- before do
436
- expect(Appsignal::Demo).to receive(:transmit).and_return(true)
437
- cli.done_notice
438
- end
572
+ expect(output).to include_env_push_api_key(push_api_key)
573
+ expect(output).to include_env_app_name(app_name)
574
+ end
439
575
 
440
- it "prints sending demo data" do
441
- expect(subject).to include "Sending example data to AppSignal", "Example data sent!"
442
- end
443
- end
576
+ it "completes the installation" do
577
+ run
444
578
 
445
- context "without demo data being sent" do
446
- before do
447
- expect(Appsignal::Demo).to receive(:transmit).and_return(false)
448
- cli.done_notice
579
+ expect(output).to include(*installation_instructions)
580
+ expect(output).to include_complete_install
581
+ end
449
582
  end
450
583
 
451
- it "prints that it couldn't send the demo data" do
452
- expect(subject).to include "Sending example data to AppSignal",
453
- "Couldn't start the AppSignal agent and send example data",
454
- "`appsignal diagnose`"
455
- end
456
- end
457
- end
458
- end
584
+ describe "configure with a configuration file" do
585
+ before { choose_config_file }
459
586
 
460
- context ".write_config_file" do
461
- before do
462
- Dir.stub(:pwd => tmp_dir)
463
- end
587
+ it_behaves_like "windows installation"
588
+ it_behaves_like "capistrano install"
589
+ it_behaves_like "demo data"
464
590
 
465
- it "should write a config file with environments" do
466
- cli.write_config_file(
467
- :push_api_key => 'key',
468
- :app_name => 'App name',
469
- :environments => [:staging, :production]
470
- )
591
+ it "writes configuration to file" do
592
+ run
471
593
 
472
- config = File.read(File.join(tmp_dir, 'config/appsignal.yml'))
594
+ expect(output).to include_file_config
595
+ expect(config_file).to configure_app_name(app_name)
596
+ expect(config_file).to configure_push_api_key(push_api_key)
597
+ expect(config_file).to configure_environment("development")
598
+ expect(config_file).to configure_environment("staging")
599
+ expect(config_file).to configure_environment("production")
600
+ end
473
601
 
474
- config.should include('name: "App name"')
475
- config.should include('push_api_key: "key"')
476
- config.should include('staging:')
477
- config.should include('production:')
602
+ it "completes the installation" do
603
+ run
604
+
605
+ expect(output).to include(*installation_instructions)
606
+ expect(output).to include_complete_install
607
+ end
608
+ end
609
+ end
478
610
  end
611
+ end
479
612
 
480
- it "should write a config file without environments" do
481
- cli.write_config_file(
482
- :push_api_key => 'key',
483
- :app_name => 'App name',
484
- :environments => []
485
- )
613
+ if !rails_present? && !sinatra_present? && !padrino_present? && !grape_present?
614
+ context "with unknown framework" do
615
+ let(:push_api_key) { "my_key" }
486
616
 
487
- config = File.read(File.join(tmp_dir, 'config/appsignal.yml'))
617
+ it_behaves_like "push_api_key validation"
488
618
 
489
- config.should include('name: "App name"')
490
- config.should include('push_api_key: "key"')
491
- config.should_not include('staging:')
492
- config.should_not include('production:')
619
+ it "prints a message about unknown framework" do
620
+ run
621
+
622
+ expect(output).to include "We could not detect which framework you are using."
623
+ expect(output).to_not include_env_push_api_key
624
+ expect(output).to_not include_env_app_name
625
+ expect(File.exist?(config_file_path)).to be_false
626
+ end
493
627
  end
494
628
  end
495
629
  end