linepipe 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 36c4f7e0578480dee9f8ce08b6c40acbc9f819ad
4
+ data.tar.gz: 6d66b0016c88478fe5d20b836eb1d584eebc8bec
5
+ SHA512:
6
+ metadata.gz: bb827c6e9d00fb5d573694c9ebe1e325f92aa2219b28bdd420ab7474da5869ca01d335a8c318e0c2efecf7f6eea0c4198f11e920904c9d1ecc2b59249db4c8a6
7
+ data.tar.gz: 15cfbada1229d2f5f8c0f6a4ff06872e587e3b584c87fa13db2ff5e531b8565c9511768017868b8b48186389cb32cc8b62226ebd214549fe2a807e76a7a9d2c3
data/README.md CHANGED
@@ -26,7 +26,8 @@ Linepipe's DSL consists of 4 different parts:
26
26
  * `setup`: Optional setup that will be run at the beginning.
27
27
  * `data`: The input data.
28
28
  * `step`: As many of these as you want will conform the steps of your
29
- algorithm.
29
+ algorithm. You can optionally provide an `expect` block that will test the
30
+ output right after than particular step.
30
31
  * `expect`: In development mode, each of these will be run against your final
31
32
  output data to ensure its conformity with your expectations.
32
33
 
@@ -42,12 +43,16 @@ linepipe = Linepipe.develop do
42
43
 
43
44
  step("Upcasing") { |data|
44
45
  data.map(&:upcase)
45
- }
46
+ }.expect('is upcased') { |data|
47
+ data.first == 'FOO'
48
+ } # as you see, each step can have its own expectations that will be tested
49
+ # when the data leaves that particular step of the pipeline
46
50
 
47
51
  step("Reversing") { |data|
48
52
  data.reverse
49
53
  }
50
54
 
55
+ # now the final expectation on the result
51
56
  expect { |data|
52
57
  data == %w(BAZ BAR FOO)
53
58
  }
@@ -88,11 +93,11 @@ linepipe = Linepipe.benchmark(10_000) do
88
93
  %w(foo bar baz)
89
94
  }
90
95
 
91
- process("Upcasing") { |data|
96
+ step("Upcasing") { |data|
92
97
  data.map(&:upcase)
93
98
  }
94
99
 
95
- process("Reversing") { |data|
100
+ step("Reversing") { |data|
96
101
  data.reverse
97
102
  }
98
103
 
data/examples/develop.rb CHANGED
@@ -10,6 +10,8 @@ class DevelopTest < MiniTest::Unit::TestCase
10
10
 
11
11
  step("Upcasing") { |data|
12
12
  data.map(&:upcase)
13
+ }.expect('is upcased') { |data|
14
+ data.first.upcase == data.first
13
15
  }
14
16
 
15
17
  step("Reversing") { |data|
data/lib/linepipe/dsl.rb CHANGED
@@ -12,7 +12,8 @@ module Linepipe
12
12
  end
13
13
 
14
14
  def step(name=nil, &block)
15
- @steps << Step.new(name, &block)
15
+ @steps << step = Step.new(name, &block)
16
+ step
16
17
  end
17
18
 
18
19
  def expect(msg=nil, &block)
@@ -27,9 +27,12 @@ module Linepipe
27
27
  run_setup
28
28
  @output = steps.to_enum.with_index.reduce(initial_data) { |d, (step, idx)|
29
29
  log "Stage #{idx}", step.name
30
- log "Input", d
31
- step.apply(d).tap do |r|
32
- log "Output", r
30
+ log "\tInput", d
31
+ step.apply(d).tap do |result|
32
+ log "\tOutput", result
33
+ step.verify_expectations(result).each do |expectation|
34
+ log "\t\t#{expectation.name}: #{expectation.status}"
35
+ end
33
36
  end
34
37
  }
35
38
 
data/lib/linepipe/step.rb CHANGED
@@ -5,14 +5,37 @@ module Linepipe
5
5
  def initialize(name=nil, &block)
6
6
  @name = name
7
7
  @block = block
8
+ @expectations = []
8
9
  end
9
10
 
10
11
  def apply(data)
11
12
  block.call(data)
12
13
  end
13
14
 
15
+ def verify_expectations(result)
16
+ @expectations.each { |exp| exp.verify(result) }
17
+ end
18
+
19
+ def expect(name=nil, &block)
20
+ @expectations << StepExpectation.new(name, &block)
21
+ end
22
+
14
23
  private
15
24
  attr_reader :block
25
+
26
+ class StepExpectation
27
+ attr_reader :name, :status
28
+
29
+ def initialize(name=nil, &test)
30
+ @name = name
31
+ @test = test
32
+ @status = 'not run'
33
+ end
34
+
35
+ def verify(data)
36
+ @status = @test.call(data) ? 'pass' : 'fail'
37
+ end
38
+ end
16
39
  end
17
40
  end
18
41
 
@@ -1,3 +1,3 @@
1
1
  module Linepipe
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -10,8 +10,8 @@ module Linepipe
10
10
  Process.new(io).tap do |process|
11
11
  process.setup { process.taint }
12
12
  process.data { %w(foo bar baz) }
13
- process.step('Upcasing') { |data| data.map(&:upcase) }
14
- process.step('Reversing', &:reverse)
13
+ process.step('Upcasing') { |data| data.map(&:upcase) }.expect('is upcased') { |data| data.first == data.first.upcase }
14
+ process.step('Reversing', &:reverse).expect('is not reversed') { |data| data.first == 'foo' } # will fail
15
15
  process.expect { |data| data.first == 'BAZ' }
16
16
  end
17
17
  end
@@ -54,6 +54,12 @@ module Linepipe
54
54
  expect(io.string).to match(/Stage 1 Reversing/)
55
55
  end
56
56
 
57
+ it 'outputs step expectation info to the io stream' do
58
+ process.develop
59
+ expect(io.string).to match(/is upcased: pass/)
60
+ expect(io.string).to match(/is not reversed: fail/)
61
+ end
62
+
57
63
  describe 'when the expectations pass' do
58
64
  it 'outputs SUCCESS' do
59
65
  process.develop
@@ -9,8 +9,26 @@ module Linepipe
9
9
  expect(step.name).to eq('upcase')
10
10
  end
11
11
 
12
- it 'calls the block with the data' do
13
- expect(step.apply('data')).to eq('DATA')
12
+ describe '#apply' do
13
+ it 'calls the block with the data' do
14
+ expect(step.apply('data')).to eq('DATA')
15
+ end
16
+ end
17
+
18
+ describe '#verify_expectations' do
19
+ context 'when there are no expectations' do
20
+ it 'returns an empty array' do
21
+ expect(step.verify_expectations('DATA')).to eq([])
22
+ end
23
+ end
24
+
25
+ it 'returns the expectations with their status' do
26
+ step.expect('is upcased') { |data| data.upcase == data }
27
+ step.expect('is downcased') { |data| data.downcase == data }
28
+ expectations = step.verify_expectations('DATA')
29
+ expect(expectations.first.status).to eq('pass')
30
+ expect(expectations.last.status).to eq('fail')
31
+ end
14
32
  end
15
33
  end
16
34
  end
metadata CHANGED
@@ -1,46 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linepipe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
5
- prerelease:
4
+ version: 0.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Josep M. Bach
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-21 00:00:00.000000000 Z
11
+ date: 2013-04-05 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rspec
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  description: Process data one step at a time.
@@ -71,33 +66,26 @@ files:
71
66
  - spec/pipeline_spec.rb
72
67
  homepage: http://wimdu.github.com/linepipe
73
68
  licenses: []
69
+ metadata: {}
74
70
  post_install_message:
75
71
  rdoc_options: []
76
72
  require_paths:
77
73
  - lib
78
74
  required_ruby_version: !ruby/object:Gem::Requirement
79
- none: false
80
75
  requirements:
81
- - - ! '>='
76
+ - - '>='
82
77
  - !ruby/object:Gem::Version
83
78
  version: '0'
84
- segments:
85
- - 0
86
- hash: 3429959400891049712
87
79
  required_rubygems_version: !ruby/object:Gem::Requirement
88
- none: false
89
80
  requirements:
90
- - - ! '>='
81
+ - - '>='
91
82
  - !ruby/object:Gem::Version
92
83
  version: '0'
93
- segments:
94
- - 0
95
- hash: 3429959400891049712
96
84
  requirements: []
97
85
  rubyforge_project:
98
- rubygems_version: 1.8.23
86
+ rubygems_version: 2.0.0
99
87
  signing_key:
100
- specification_version: 3
88
+ specification_version: 4
101
89
  summary: Process data one step at a time.
102
90
  test_files:
103
91
  - spec/pipeline/expectation_spec.rb