/
example_1_spec.rb
74 lines (61 loc) · 1.94 KB
/
example_1_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# frozen_string_literal: true
require 'spec_helper'
module Readme
class Example1
include RailwayOperation
operation do |o|
o.add_step 1, :first_method
o.add_step 1, :another_method
o.add_step 1, :final_method
end
def initialize(someone = 'someone')
@someone = someone
end
def first_method(argument, **)
argument << "Hello #{@someone}, from first_method."
end
def another_method(argument, **)
argument << 'Hello from another_method.'
end
def final_method(argument, **)
argument << 'Hello from final_method.'
end
end
end
describe Readme::Example1 do
let(:argument) { [] }
it 'executes methods in the order they are specified' do
result, info = described_class.run(argument)
expect(result).to eq(
[
'Hello someone, from first_method.',
'Hello from another_method.',
'Hello from final_method.'
]
)
expect(info.execution.all?(&:completed?)).to eq(true)
expect(info.execution).to be_success
expect(info.execution).to_not be_failed
expect(info.execution.display).to eq(
"+---+-------+---------+----------------+--------+\n"\
"| Execution |\n"\
"+---+-------+---------+----------------+--------+\n"\
"| | Track | Success | Method | Errors |\n"\
"+---+-------+---------+----------------+--------+\n"\
"| 0 | 1 | true | first_method | [] |\n"\
"| 1 | 1 | true | another_method | [] |\n"\
"| 2 | 1 | true | final_method | [] |\n"\
'+---+-------+---------+----------------+--------+'
)
end
it 'executes operation with the initialized parameter' do
result, _info = described_class.new('Felix').run(argument)
expect(result).to eq(
[
'Hello Felix, from first_method.',
'Hello from another_method.',
'Hello from final_method.'
]
)
end
end