turbot-runner-morph 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YzIwY2EwYmEzZDE4ODYyNWY5NTM2MDBjOGRkOGY3NjU5ZjE1OGNjYQ==
4
+ MzEwODljYjAwYTk0OTJmYjBlNGE4M2Y2MjU1YWMyZGQ3Yjg4N2U5MQ==
5
5
  data.tar.gz: !binary |-
6
- ZmY2NDJiODhmYmJhODNjNGJjMWI3MGU2YjliMTc3ZWMyMDI1NmY0MQ==
6
+ OTFiYmEwN2U1NjdhYzE0Zjc0MTU2YWNiYWExMzdjNmM4NTdjZDI0ZA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NTBhMGM4ODkyNThmYzJmMjkyZTQ0M2VlZDNjODY2Y2YzNmFhM2EzMTU1YmY5
10
- ODUzMTM0NzA3YWFkZDk0YTIxMzc4NTZiYWVjY2IzNWRkNzk4YWNiNjMxOTVi
11
- ZGI1Nzc5YzYzNzI3YzAxZTg4NjI3MzM3ZjgxY2I2NmYxNjZmOWQ=
9
+ YmZlNDk4NDhkNWIwMTUwNjNlNzJjZDQ1MGFhYTg4ODQwMmJlYTFjMDJhYWYz
10
+ MWIwZmI2ZDk0NjcxNmNhZjJlYjllYjVkZTBmN2M0YTNmNzRhNjI0MDFkNTlh
11
+ MmMwMmU3OTcxZjk1NWMzZGRjY2QxNTI1N2M0MThlMjU3MjBlNDA=
12
12
  data.tar.gz: !binary |-
13
- MjM3YjU4YWU5MmNlODgzN2JjNTQxMjM2Yzc0MDFlM2M4ODI1OGVkNGIyMzJl
14
- YzUxZjVkNjMzZDAzYzUxY2JkNDMwYTE4ZmYwZmM0YTZjOGMzODEwMzExYmFm
15
- Yzc0MmIzODY3Y2E3Njg1NWI3MjczNWI5NWQxNDVhNGEyYjU4NzM=
13
+ YmRmODk5YTQyOGRkMTVmYzcwMjVhYmFmZTA4Y2Q1NDE5ZmVhOTkzYTc5ZDhh
14
+ NDBjNTYwYzc2ODQzNGQ5ZjJmMTQ0Y2Y0MDA5YTYyOWE2NWI2NDI2ZDIxY2Jl
15
+ ZTRiYmY3ZTc4M2ExZTk1MTViMGZjZmJiYzU4MjU2ODJkMWE2YWM=
@@ -4,6 +4,10 @@ require 'pathname'
4
4
 
5
5
  module TurbotRunner
6
6
  class Runner
7
+ RC_OK = 0
8
+ RC_SCRAPER_FAILED = 1
9
+ RC_TRANSFORMER_FAILED = 2
10
+
7
11
  attr_reader :base_directory
8
12
 
9
13
  def initialize(directory, options={})
@@ -19,29 +23,47 @@ module TurbotRunner
19
23
  else
20
24
  @output_directory = File.join(@base_directory, 'output')
21
25
  end
26
+ @scraper_provided = options[:scraper_provided]
22
27
  end
23
28
 
24
29
  def run
25
30
  set_up_output_directory
26
31
 
27
- succeeded = run_script(scraper_config)
32
+ if @scraper_provided
33
+ scraper_succeeded = true
34
+ else
35
+ scraper_succeeded = run_script(scraper_config)
36
+ end
37
+
28
38
  # Run the transformers even if the scraper fails
39
+ transformers_succeeded = true
29
40
  transformers.each do |transformer_config|
30
- succeeded = run_script(
31
- transformer_config.merge(:base_directory => @base_directory),
32
- input_file=scraper_output_file) && succeeded
41
+ config = transformer_config.merge(
42
+ :base_directory => @base_directory,
43
+ )
44
+ transformers_succeeded = run_script(config, input_file=scraper_output_file) && transformers_succeeded
45
+ end
46
+
47
+ if !scraper_succeeded
48
+ RC_SCRAPER_FAILED
49
+ elsif !transformers_succeeded
50
+ RC_TRANSFORMER_FAILED
51
+ else
52
+ RC_OK
33
53
  end
34
- succeeded
35
54
  end
36
55
 
37
56
  def set_up_output_directory
38
57
  FileUtils.mkdir_p(@output_directory)
39
- FileUtils.rm_f(File.join(@output_directory, 'scraper.out'))
40
- FileUtils.rm_f(File.join(@output_directory, 'scraper.err'))
58
+
59
+ if !@scraper_provided
60
+ FileUtils.rm_f(output_file('scraper', '.out'))
61
+ FileUtils.rm_f(output_file('scraper', '.err'))
62
+ end
41
63
 
42
64
  transformers.each do |transformer_config|
43
- FileUtils.rm_f(File.join(@output_directory, "#{transformer_config[:file]}.out"))
44
- FileUtils.rm_f(File.join(@output_directory, "#{transformer_config[:file]}.err"))
65
+ FileUtils.rm_f(output_file(transformer_config[:file], '.out'))
66
+ FileUtils.rm_f(output_file(transformer_config[:file], '.err'))
45
67
  end
46
68
  end
47
69
 
@@ -1,3 +1,3 @@
1
1
  module TurbotRunner
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
@@ -2,10 +2,6 @@ require 'json'
2
2
  require 'turbot_runner'
3
3
 
4
4
  describe TurbotRunner::Runner do
5
- before(:each) do
6
- Dir.glob('spec/bots/**/output/*').each {|f| File.delete(f)}
7
- end
8
-
9
5
  after(:all) do
10
6
  puts
11
7
  puts 'If all specs passed, you should now run `ruby spec/manual_spec.rb`'
@@ -19,11 +15,11 @@ describe TurbotRunner::Runner do
19
15
 
20
16
  it 'produces expected output' do
21
17
  @runner.run
22
- expect([@runner, 'scraper']).to have_output('full-scraper.out')
18
+ expect(@runner).to have_output('scraper', 'full-scraper.out')
23
19
  end
24
20
 
25
21
  it 'returns true' do
26
- expect(@runner.run).to be(true)
22
+ expect(@runner).to succeed
27
23
  end
28
24
  end
29
25
 
@@ -34,7 +30,7 @@ describe TurbotRunner::Runner do
34
30
 
35
31
  it 'produces expected output' do
36
32
  @runner.run
37
- expect([@runner, 'scraper']).to have_output('full-scraper.out')
33
+ expect(@runner).to have_output('scraper', 'full-scraper.out')
38
34
  end
39
35
  end
40
36
 
@@ -45,12 +41,12 @@ describe TurbotRunner::Runner do
45
41
 
46
42
  it 'produces expected outputs' do
47
43
  @runner.run
48
- expect([@runner, 'scraper']).to have_output('full-scraper.out')
49
- expect([@runner, 'transformer']).to have_output('full-transformer.out')
44
+ expect(@runner).to have_output('scraper', 'full-scraper.out')
45
+ expect(@runner).to have_output('transformer', 'full-transformer.out')
50
46
  end
51
47
 
52
48
  it 'returns true' do
53
- expect(@runner.run).to be(true)
49
+ expect(@runner).to succeed
54
50
  end
55
51
  end
56
52
 
@@ -61,13 +57,13 @@ describe TurbotRunner::Runner do
61
57
 
62
58
  it 'produces expected outputs' do
63
59
  @runner.run
64
- expect([@runner, 'scraper']).to have_output('full-scraper.out')
65
- expect([@runner, 'transformer1']).to have_output('full-transformer.out')
66
- expect([@runner, 'transformer2']).to have_output('full-transformer.out')
60
+ expect(@runner).to have_output('scraper', 'full-scraper.out')
61
+ expect(@runner).to have_output('transformer1', 'full-transformer.out')
62
+ expect(@runner).to have_output('transformer2', 'full-transformer.out')
67
63
  end
68
64
 
69
65
  it 'returns true' do
70
- expect(@runner.run).to be(true)
66
+ expect(@runner).to succeed
71
67
  end
72
68
  end
73
69
 
@@ -77,7 +73,7 @@ describe TurbotRunner::Runner do
77
73
  expected_log = "doing...\ndone\n"
78
74
  runner = test_runner('logging-bot', :log_to_file => true)
79
75
  runner.run
80
- expect([runner, 'scraper']).to have_error_output_matching(expected_log)
76
+ expect(runner).to have_error_output_matching('scraper', expected_log)
81
77
  end
82
78
  end
83
79
 
@@ -110,12 +106,12 @@ describe TurbotRunner::Runner do
110
106
  end
111
107
 
112
108
  it 'returns false' do
113
- expect(@runner.run).to be(false)
109
+ expect(@runner).to fail_in_scraper
114
110
  end
115
111
 
116
112
  it 'writes error to stderr' do
117
113
  @runner.run
118
- expect([@runner, 'scraper']).to have_error_output_matching(/Oh no/)
114
+ expect(@runner).to have_error_output_matching('scraper', /Oh no/)
119
115
  end
120
116
 
121
117
  it 'still runs the transformers' do
@@ -133,7 +129,7 @@ describe TurbotRunner::Runner do
133
129
  end
134
130
 
135
131
  it 'returns true' do
136
- expect(@runner.run).to be(true)
132
+ expect(@runner).to succeed
137
133
  end
138
134
  end
139
135
 
@@ -143,12 +139,12 @@ describe TurbotRunner::Runner do
143
139
  end
144
140
 
145
141
  it 'returns false' do
146
- expect(@runner.run).to be(false)
142
+ expect(@runner).to fail_in_transformer
147
143
  end
148
144
 
149
145
  it 'writes error to stderr' do
150
146
  @runner.run
151
- expect([@runner, 'transformer2']).to have_error_output_matching(/Oh no/)
147
+ expect(@runner).to have_error_output_matching('transformer2', /Oh no/)
152
148
  end
153
149
  end
154
150
 
@@ -180,25 +176,25 @@ describe TurbotRunner::Runner do
180
176
 
181
177
  it 'produces expected output' do
182
178
  @runner.run
183
- expect([@runner, 'scraper']).to have_output('truncated-scraper.out')
179
+ expect(@runner).to have_output('scraper', 'truncated-scraper.out')
184
180
  end
185
181
 
186
182
  it 'returns true' do
187
- expect(@runner.run).to be(true)
183
+ expect(@runner).to succeed
188
184
  end
189
185
  end
190
186
 
191
187
  context 'with a scraper that produces an invalid record' do
192
188
  it 'returns false' do
193
189
  @runner = test_runner('invalid-record-bot')
194
- expect(@runner.run).to be(false)
190
+ expect(@runner).to fail_in_scraper
195
191
  end
196
192
  end
197
193
 
198
194
  context 'with a scraper that produces invalid JSON' do
199
195
  it 'returns false' do
200
196
  @runner = test_runner('invalid-json-bot')
201
- expect(@runner.run).to be(false)
197
+ expect(@runner).to fail_in_scraper
202
198
  end
203
199
  end
204
200
 
@@ -213,7 +209,7 @@ describe TurbotRunner::Runner do
213
209
  :timeout => 1,
214
210
  :log_to_file => true
215
211
  )
216
- expect(@runner.run).to be(false)
212
+ expect(@runner).to fail_in_scraper
217
213
  end
218
214
  end
219
215
 
@@ -223,7 +219,7 @@ describe TurbotRunner::Runner do
223
219
  end
224
220
 
225
221
  it 'returns false' do
226
- expect(@runner.run).to be(false)
222
+ expect(@runner).to fail_in_scraper
227
223
  end
228
224
  end
229
225
 
@@ -236,6 +232,32 @@ describe TurbotRunner::Runner do
236
232
  expect{@runner.run}.to raise_error(TurbotRunner::InvalidDataType)
237
233
  end
238
234
  end
235
+
236
+ context 'when the scraped data is provided' do
237
+ before do
238
+ FileUtils.cp(
239
+ File.join('spec', 'outputs', 'full-scraper.out'),
240
+ File.join(File.dirname(__FILE__), '../bots', 'bot-with-transformer', 'output', 'scraper.out')
241
+ )
242
+ @runner = test_runner('bot-with-transformer', :scraper_provided => true)
243
+ end
244
+
245
+ it 'does not run scraper' do
246
+ expect(@runner).to receive(:run_script).once.with(
247
+ hash_including(:file => 'transformer.rb'), anything
248
+ )
249
+ @runner.run
250
+ end
251
+
252
+ it 'succeeds' do
253
+ expect(@runner).to succeed
254
+ end
255
+
256
+ it 'produces expected transformed output' do
257
+ @runner.run
258
+ expect(@runner).to have_output('transformer', 'full-transformer.out')
259
+ end
260
+ end
239
261
  end
240
262
 
241
263
  describe '#process_output' do
@@ -301,10 +323,8 @@ describe TurbotRunner::Runner do
301
323
  end
302
324
 
303
325
 
304
- RSpec::Matchers.define :have_output do |expected|
305
- match do |actual|
306
- runner, script = actual
307
-
326
+ RSpec::Matchers.define(:have_output) do |script, expected|
327
+ match do |runner|
308
328
  expected_path = File.join('spec', 'outputs', expected)
309
329
  expected_output = File.readlines(expected_path).map {|line| JSON.parse(line)}
310
330
  actual_path = File.join(runner.base_directory, 'output', "#{script}.out")
@@ -314,16 +334,35 @@ RSpec::Matchers.define :have_output do |expected|
314
334
  end
315
335
 
316
336
 
317
- RSpec::Matchers.define :have_error_output_matching do |expected|
318
- match do |actual|
319
- runner, script = actual
320
-
337
+ RSpec::Matchers.define(:have_error_output_matching) do |script, expected|
338
+ match do |runner|
321
339
  actual_path = File.join(runner.base_directory, 'output', "#{script}.err")
322
340
  actual_output = File.read(actual_path)
323
341
  expect(actual_output).to match(expected)
324
342
  end
325
343
  end
326
344
 
345
+
346
+ RSpec::Matchers.define(:succeed) do
347
+ match do |runner|
348
+ expect(runner.run).to eq(TurbotRunner::Runner::RC_OK)
349
+ end
350
+ end
351
+
352
+
353
+ RSpec::Matchers.define(:fail_in_scraper) do
354
+ match do |runner|
355
+ expect(runner.run).to eq(TurbotRunner::Runner::RC_SCRAPER_FAILED)
356
+ end
357
+ end
358
+
359
+
360
+ RSpec::Matchers.define(:fail_in_transformer) do
361
+ match do |runner|
362
+ expect(runner.run).to eq(TurbotRunner::Runner::RC_TRANSFORMER_FAILED)
363
+ end
364
+ end
365
+
327
366
  def test_runner(name, opts={})
328
367
  test_bot_location = File.join(File.dirname(__FILE__), '../bots', name)
329
368
  TurbotRunner::Runner.new(test_bot_location, opts)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turbot-runner-morph
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - OpenCorporates
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-21 00:00:00.000000000 Z
11
+ date: 2015-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: openc-json_schema