response_mate 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -1
- data/Gemfile.lock +1 -1
- data/lib/response_mate/cli.rb +1 -0
- data/lib/response_mate/commands/record.rb +1 -4
- data/lib/response_mate/recorder.rb +7 -2
- data/lib/response_mate/tape.rb +3 -2
- data/lib/response_mate/version.rb +1 -1
- data/spec/lib/response_mate/commands/record_spec.rb +44 -0
- data/spec/lib/response_mate/tape_spec.rb +32 -2
- metadata +4 -2
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/lib/response_mate/cli.rb
CHANGED
@@ -6,6 +6,7 @@ module ResponseMate
|
|
6
6
|
|
7
7
|
desc 'record', 'Perform requests and record their output'
|
8
8
|
method_option :requests_manifest, aliases: '-r'
|
9
|
+
method_option :output_dir, aliases: '-o', type: :string
|
9
10
|
method_option :keys, aliases: '-k', type: :array, default: []
|
10
11
|
def record
|
11
12
|
ResponseMate::Commands::Record.new(args, options).run
|
@@ -9,13 +9,10 @@ module ResponseMate
|
|
9
9
|
manifest = ResponseMate::Manifest.new(options[:requests_manifest], environment)
|
10
10
|
|
11
11
|
options[:manifest] = manifest
|
12
|
+
|
12
13
|
recorder = ResponseMate::Recorder.new(options)
|
13
14
|
|
14
15
|
recorder.record(options[:keys])
|
15
|
-
|
16
|
-
File.open(ResponseMate.configuration.output_dir + '.last_recording', 'w') do |f|
|
17
|
-
f << Time.current
|
18
|
-
end
|
19
16
|
end
|
20
17
|
end
|
21
18
|
end
|
@@ -3,11 +3,12 @@
|
|
3
3
|
module ResponseMate
|
4
4
|
# Handles recording requests
|
5
5
|
class Recorder
|
6
|
-
attr_accessor :conn, :manifest, :keys
|
6
|
+
attr_accessor :conn, :manifest, :keys, :output_dir
|
7
7
|
|
8
8
|
def initialize(args = {})
|
9
9
|
@manifest = args[:manifest]
|
10
10
|
@conn = ResponseMate::Connection.new
|
11
|
+
@output_dir = args[:output_dir]
|
11
12
|
end
|
12
13
|
|
13
14
|
def record(keys)
|
@@ -22,7 +23,11 @@ module ResponseMate
|
|
22
23
|
meta = request.meta
|
23
24
|
puts request.to_cli_format
|
24
25
|
|
25
|
-
ResponseMate::Tape.new.write(request.key,
|
26
|
+
ResponseMate::Tape.new.write(request.key,
|
27
|
+
request,
|
28
|
+
conn.fetch(request),
|
29
|
+
meta,
|
30
|
+
output_dir)
|
26
31
|
end
|
27
32
|
end
|
28
33
|
end
|
data/lib/response_mate/tape.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
class ResponseMate::Tape
|
4
|
-
def write(key, request, response, meta = {})
|
5
|
-
output_dir = ResponseMate.configuration.output_dir
|
4
|
+
def write(key, request, response, meta = {}, output_dir = nil)
|
5
|
+
output_dir = output_dir || ResponseMate.configuration.output_dir
|
6
|
+
|
6
7
|
output_path = File.join output_dir, "#{key}.yml"
|
7
8
|
|
8
9
|
File.open(output_path, 'w') do |f|
|
@@ -18,6 +18,50 @@ describe ResponseMate::Commands::Record do
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
+
context 'with output_dir option specified' do
|
22
|
+
let(:other_output_dir) do
|
23
|
+
File.expand_path('spec/source/other_output_dir')
|
24
|
+
end
|
25
|
+
|
26
|
+
let(:cmd_with_output_dir) do
|
27
|
+
quietly do
|
28
|
+
ResponseMate::Commands::Record.new([], {
|
29
|
+
keys: [],
|
30
|
+
output_dir: [other_output_dir]
|
31
|
+
}).run
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'when the specified directory exists' do
|
36
|
+
let(:output_files) { ->{ Dir[other_output_dir + '/*'] } }
|
37
|
+
|
38
|
+
before { cmd_with_output_dir }
|
39
|
+
after { output_files.call.each { |file| File.delete(file) } }
|
40
|
+
|
41
|
+
it 'created the tapes in the specified directory' do
|
42
|
+
expect(output_files.call).to have_exactly(2).items
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'when the specified directory does not exist' do
|
47
|
+
let(:other_output_dir) do
|
48
|
+
File.expand_path('spec/source/i_do_not_exist')
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'raises ResponeMate::OutputDirError' do
|
52
|
+
expect { cmd_with_output_dir }.to raise_error(ResponseMate::OutputDirError)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'with output_dir option unspecified' do
|
58
|
+
it 'creates the tapes in the default output directory' do
|
59
|
+
quietly { ResponseMate::Commands::Record.new([], { keys: [] }).run }
|
60
|
+
|
61
|
+
expect(output_files.call).to have_exactly(2).items
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
21
65
|
context 'with keys option specified' do
|
22
66
|
context 'when the requested key exists' do
|
23
67
|
before do
|
@@ -28,15 +28,45 @@ describe ResponseMate::Tape do
|
|
28
28
|
describe '#write' do
|
29
29
|
let(:tape) { YAML.load_file(output_files.call.last) }
|
30
30
|
|
31
|
-
|
32
|
-
|
31
|
+
let(:output_dir) { nil }
|
32
|
+
|
33
|
+
let(:write) do
|
34
|
+
ResponseMate::Tape.new.write(key, request, response, meta, output_dir)
|
33
35
|
end
|
34
36
|
|
37
|
+
subject { write }
|
38
|
+
|
35
39
|
it 'creates a new tape with key parameter as the filename' do
|
40
|
+
subject
|
36
41
|
expect(File.basename(output_files.call.last)).to eq("#{key}.yml")
|
37
42
|
end
|
38
43
|
|
44
|
+
describe 'tape location' do
|
45
|
+
context 'when the specified output_dir exists' do
|
46
|
+
let(:output_dir) { File.expand_path('./spec/source/other_output_dir') }
|
47
|
+
let(:output_files) { ->{ Dir[output_dir + '/*'] } }
|
48
|
+
|
49
|
+
after { output_files.call.each { |file| File.delete(file) } }
|
50
|
+
|
51
|
+
it 'is inside the specified output_dir' do
|
52
|
+
subject
|
53
|
+
expect(tape).to be
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'when the specified output_dir does not exist' do
|
58
|
+
let(:output_dir) do
|
59
|
+
File.expand_path('spec/source/i_do_not_exist')
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'raises ResponeMate::OutputDirError' do
|
63
|
+
expect { subject }.to raise_error(ResponseMate::OutputDirError)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
39
68
|
describe 'the created tape' do
|
69
|
+
before { write }
|
40
70
|
subject { tape }
|
41
71
|
|
42
72
|
it 'is valid YAML' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: response_mate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-07-
|
12
|
+
date: 2014-07-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -246,6 +246,7 @@ files:
|
|
246
246
|
- spec/lib/response_mate/tape_spec.rb
|
247
247
|
- spec/lib/response_mate_spec.rb
|
248
248
|
- spec/source/environment.yml
|
249
|
+
- spec/source/other_output_dir/.gitkeep
|
249
250
|
- spec/source/requests.yml
|
250
251
|
- spec/source/responses/.gitkeep
|
251
252
|
- spec/spec_helper.rb
|
@@ -287,6 +288,7 @@ test_files:
|
|
287
288
|
- spec/lib/response_mate/tape_spec.rb
|
288
289
|
- spec/lib/response_mate_spec.rb
|
289
290
|
- spec/source/environment.yml
|
291
|
+
- spec/source/other_output_dir/.gitkeep
|
290
292
|
- spec/source/requests.yml
|
291
293
|
- spec/source/responses/.gitkeep
|
292
294
|
- spec/spec_helper.rb
|