torkify 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -1
  3. data/.travis.yml +6 -0
  4. data/README.md +8 -2
  5. data/VERSION +1 -1
  6. data/lib/torkify/conductor.rb +25 -14
  7. data/lib/torkify/{events/event.rb → event/basic_event.rb} +4 -4
  8. data/lib/torkify/event/dispatcher.rb +91 -0
  9. data/lib/torkify/event/echo_event.rb +23 -0
  10. data/lib/torkify/{events/event_message.rb → event/message.rb} +2 -2
  11. data/lib/torkify/event/parser.rb +70 -0
  12. data/lib/torkify/{events → event}/pass_or_fail_event.rb +15 -3
  13. data/lib/torkify/event/ran_all_test_files_event.rb +30 -0
  14. data/lib/torkify/{events → event}/status_change_event.rb +3 -3
  15. data/lib/torkify/{events → event}/test_event.rb +4 -3
  16. data/lib/torkify/listener.rb +17 -8
  17. data/lib/torkify/log/line_matcher.rb +33 -0
  18. data/lib/torkify/log/log_reader.rb +32 -0
  19. data/lib/torkify/log/parser.rb +96 -0
  20. data/lib/torkify/log/test_error.rb +7 -0
  21. data/lib/torkify/reader.rb +7 -5
  22. data/lib/torkify/version.rb +1 -1
  23. data/lib/torkify.rb +2 -3
  24. data/spec/conductor_spec.rb +3 -4
  25. data/spec/event/basic_event_spec.rb +30 -0
  26. data/spec/event/dispatcher_spec.rb +190 -0
  27. data/spec/event/echo_event_spec.rb +22 -0
  28. data/spec/event/parser_spec.rb +288 -0
  29. data/spec/{pass_or_fail_event_spec.rb → event/pass_or_fail_event_spec.rb} +2 -2
  30. data/spec/event/ran_all_test_files_event_spec.rb +42 -0
  31. data/spec/{status_change_event_spec.rb → event/status_change_event_spec.rb} +3 -3
  32. data/spec/{test_event_spec.rb → event/test_event_spec.rb} +2 -2
  33. data/spec/log/integration_spec.rb +222 -0
  34. data/spec/log/line_matcher_spec.rb +247 -0
  35. data/spec/log/log_reader_spec.rb +54 -0
  36. data/spec/log/logs/invalid_ruby_error_1.log +1 -0
  37. data/spec/log/logs/rspec_failure_1.log +19 -0
  38. data/spec/log/logs/rspec_failure_2.log +57 -0
  39. data/spec/log/logs/ruby_error_1.log +16 -0
  40. data/spec/log/logs/ruby_error_2.log +17 -0
  41. data/spec/log/logs/ruby_error_3.log +18 -0
  42. data/spec/log/logs/test_unit_error_1.log +22 -0
  43. data/spec/log/logs/test_unit_failure_1.log +22 -0
  44. data/spec/log/test_error_spec.rb +36 -0
  45. data/torkify.gemspec +1 -1
  46. metadata +63 -40
  47. data/lib/torkify/event_parser.rb +0 -36
  48. data/lib/torkify/observer_set.rb +0 -62
  49. data/spec/event_parser_spec.rb +0 -154
  50. data/spec/event_spec.rb +0 -18
  51. data/spec/observer_set_spec.rb +0 -100
@@ -0,0 +1,22 @@
1
+ Run options: --name "/(?i:a.*user)/" --seed 28304
2
+
3
+ # Running tests:
4
+
5
+
6
+
7
+ Finished tests in 0.000398s, 0.0000 tests/s, 0.0000 assertions/s.
8
+
9
+ 0 tests, 0 assertions, 0 failures, 0 errors, 0 skips
10
+ Loaded suite tork-worker[0] test/integration/user_flows_test
11
+ Started
12
+ ..E.
13
+
14
+ 1) Error:
15
+ test: a user should redirect to admin login when visiting admin subdomain. (UserFlowsTest):
16
+ NameError: undefined local variable or method `root_pathh' for #<UserFlowsTest:0x000000036f2388>
17
+ test/integration/user_flows_test.rb:8:in `block (2 levels) in <class:UserFlowsTest>'
18
+
19
+ Finished in 1.0396772 seconds.
20
+
21
+ 4 tests, 3 assertions, 0 failures, 1 errors, 0 pendings, 0 omissions, 0 notifications
22
+ 75% passed
@@ -0,0 +1,22 @@
1
+ Run options: --seed 14022
2
+
3
+ # Running tests:
4
+
5
+
6
+
7
+ Finished tests in 0.000474s, 0.0000 tests/s, 0.0000 assertions/s.
8
+
9
+ 0 tests, 0 assertions, 0 failures, 0 errors, 0 skips
10
+ Loaded suite tork-worker[1] test/unit/address_test
11
+ Started
12
+ .F....
13
+
14
+ 1) Failure:
15
+ test: Address should have many companie. (AddressTest)
16
+ []:
17
+ Expected Address to have a has_many association called companie (no association called companie)
18
+
19
+ Finished in 0.49262291 seconds.
20
+
21
+ 6 tests, 6 assertions, 1 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
22
+ 83.3333% passed
@@ -0,0 +1,36 @@
1
+ require 'torkify/log/parser'
2
+ require 'spec_helper'
3
+
4
+ module Torkify::Log
5
+ describe TestError do
6
+
7
+ shared_examples "an error" do
8
+ let(:error) { TestError.new filename, lnum, text, type }
9
+
10
+ subject { error }
11
+
12
+ its(:filename) { should == filename }
13
+ its(:lnum) { should == lnum }
14
+ its(:text) { should == text }
15
+ its(:type) { should == type }
16
+ end
17
+
18
+ context "with some sample data" do
19
+ let(:filename) { '/path/to/file.rb' }
20
+ let(:lnum) { 23 }
21
+ let(:text) { 'this is an error message' }
22
+ let(:type) { 'F' }
23
+
24
+ it_behaves_like "an error"
25
+ end
26
+
27
+ context "with some alternative sample data" do
28
+ let(:filename) { 'path/to/another/file.rb' }
29
+ let(:lnum) { 47 }
30
+ let(:text) { 'A totally different error message' }
31
+ let(:type) { 'E' }
32
+
33
+ it_behaves_like "an error"
34
+ end
35
+ end
36
+ end
data/torkify.gemspec CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |gem|
14
14
 
15
15
  gem.add_dependency 'json', '~> 1.7.7'
16
16
  gem.add_dependency 'log4r', '~> 1.1.10'
17
- gem.add_dependency 'tork', '~> 19.2.1'
17
+ gem.add_dependency 'tork', '~> 19.2'
18
18
 
19
19
  gem.add_development_dependency 'rspec', '~> 2.13.0'
20
20
  gem.add_development_dependency 'rake', '~> 10.0.3'
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: torkify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: 0.0.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Jon Cairns
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-04-05 00:00:00.000000000 Z
11
+ date: 2014-08-08 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: json
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
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
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: log4r
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :runtime
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
@@ -46,23 +41,20 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: tork
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
53
- version: 19.2.1
47
+ version: '19.2'
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
61
- version: 19.2.1
54
+ version: '19.2'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rspec
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ~>
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ~>
76
67
  - !ruby/object:Gem::Version
@@ -78,7 +69,6 @@ dependencies:
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: rake
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
73
  - - ~>
84
74
  - !ruby/object:Gem::Version
@@ -86,7 +76,6 @@ dependencies:
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
80
  - - ~>
92
81
  - !ruby/object:Gem::Version
@@ -99,6 +88,7 @@ extensions: []
99
88
  extra_rdoc_files: []
100
89
  files:
101
90
  - .gitignore
91
+ - .travis.yml
102
92
  - Gemfile
103
93
  - LICENSE.txt
104
94
  - README.md
@@ -106,63 +96,96 @@ files:
106
96
  - VERSION
107
97
  - lib/torkify.rb
108
98
  - lib/torkify/conductor.rb
109
- - lib/torkify/event_parser.rb
110
- - lib/torkify/events/event.rb
111
- - lib/torkify/events/event_message.rb
112
- - lib/torkify/events/pass_or_fail_event.rb
113
- - lib/torkify/events/status_change_event.rb
114
- - lib/torkify/events/test_event.rb
99
+ - lib/torkify/event/basic_event.rb
100
+ - lib/torkify/event/dispatcher.rb
101
+ - lib/torkify/event/echo_event.rb
102
+ - lib/torkify/event/message.rb
103
+ - lib/torkify/event/parser.rb
104
+ - lib/torkify/event/pass_or_fail_event.rb
105
+ - lib/torkify/event/ran_all_test_files_event.rb
106
+ - lib/torkify/event/status_change_event.rb
107
+ - lib/torkify/event/test_event.rb
115
108
  - lib/torkify/exceptions.rb
116
109
  - lib/torkify/listener.rb
117
- - lib/torkify/observer_set.rb
110
+ - lib/torkify/log/line_matcher.rb
111
+ - lib/torkify/log/log_reader.rb
112
+ - lib/torkify/log/parser.rb
113
+ - lib/torkify/log/test_error.rb
118
114
  - lib/torkify/reader.rb
119
115
  - lib/torkify/version.rb
120
116
  - spec/conductor_spec.rb
121
- - spec/event_parser_spec.rb
122
- - spec/event_spec.rb
117
+ - spec/event/basic_event_spec.rb
118
+ - spec/event/dispatcher_spec.rb
119
+ - spec/event/echo_event_spec.rb
120
+ - spec/event/parser_spec.rb
121
+ - spec/event/pass_or_fail_event_spec.rb
122
+ - spec/event/ran_all_test_files_event_spec.rb
123
+ - spec/event/status_change_event_spec.rb
124
+ - spec/event/test_event_spec.rb
123
125
  - spec/listener_spec.rb
124
- - spec/observer_set_spec.rb
125
- - spec/pass_or_fail_event_spec.rb
126
+ - spec/log/integration_spec.rb
127
+ - spec/log/line_matcher_spec.rb
128
+ - spec/log/log_reader_spec.rb
129
+ - spec/log/logs/invalid_ruby_error_1.log
130
+ - spec/log/logs/rspec_failure_1.log
131
+ - spec/log/logs/rspec_failure_2.log
132
+ - spec/log/logs/ruby_error_1.log
133
+ - spec/log/logs/ruby_error_2.log
134
+ - spec/log/logs/ruby_error_3.log
135
+ - spec/log/logs/test_unit_error_1.log
136
+ - spec/log/logs/test_unit_failure_1.log
137
+ - spec/log/test_error_spec.rb
126
138
  - spec/reader_spec.rb
127
139
  - spec/spec_helper.rb
128
- - spec/status_change_event_spec.rb
129
- - spec/test_event_spec.rb
130
140
  - torkify.gemspec
131
141
  homepage: https://github.com/joonty/torkify
132
142
  licenses: []
143
+ metadata: {}
133
144
  post_install_message:
134
145
  rdoc_options: []
135
146
  require_paths:
136
147
  - lib
137
148
  required_ruby_version: !ruby/object:Gem::Requirement
138
- none: false
139
149
  requirements:
140
- - - ! '>='
150
+ - - '>='
141
151
  - !ruby/object:Gem::Version
142
152
  version: '0'
143
153
  required_rubygems_version: !ruby/object:Gem::Requirement
144
- none: false
145
154
  requirements:
146
- - - ! '>='
155
+ - - '>='
147
156
  - !ruby/object:Gem::Version
148
157
  version: '0'
149
158
  requirements: []
150
159
  rubyforge_project:
151
- rubygems_version: 1.8.24
160
+ rubygems_version: 2.2.2
152
161
  signing_key:
153
- specification_version: 3
162
+ specification_version: 4
154
163
  summary: Torkify allows you to execute code after tests run, when using the tork gem
155
164
  for automated testing. You can create listeners which are called when tests are
156
165
  run, and when they fail or pass. This allows you to easily execute code and call
157
166
  system programs.
158
167
  test_files:
159
168
  - spec/conductor_spec.rb
160
- - spec/event_parser_spec.rb
161
- - spec/event_spec.rb
169
+ - spec/event/basic_event_spec.rb
170
+ - spec/event/dispatcher_spec.rb
171
+ - spec/event/echo_event_spec.rb
172
+ - spec/event/parser_spec.rb
173
+ - spec/event/pass_or_fail_event_spec.rb
174
+ - spec/event/ran_all_test_files_event_spec.rb
175
+ - spec/event/status_change_event_spec.rb
176
+ - spec/event/test_event_spec.rb
162
177
  - spec/listener_spec.rb
163
- - spec/observer_set_spec.rb
164
- - spec/pass_or_fail_event_spec.rb
178
+ - spec/log/integration_spec.rb
179
+ - spec/log/line_matcher_spec.rb
180
+ - spec/log/log_reader_spec.rb
181
+ - spec/log/logs/invalid_ruby_error_1.log
182
+ - spec/log/logs/rspec_failure_1.log
183
+ - spec/log/logs/rspec_failure_2.log
184
+ - spec/log/logs/ruby_error_1.log
185
+ - spec/log/logs/ruby_error_2.log
186
+ - spec/log/logs/ruby_error_3.log
187
+ - spec/log/logs/test_unit_error_1.log
188
+ - spec/log/logs/test_unit_failure_1.log
189
+ - spec/log/test_error_spec.rb
165
190
  - spec/reader_spec.rb
166
191
  - spec/spec_helper.rb
167
- - spec/status_change_event_spec.rb
168
- - spec/test_event_spec.rb
@@ -1,36 +0,0 @@
1
- require 'json'
2
- require_relative 'events/event'
3
- require_relative 'events/test_event'
4
- require_relative 'events/pass_or_fail_event'
5
- require_relative 'events/status_change_event'
6
-
7
- module Torkify
8
-
9
- # Parse raw strings passed by tork into event objects.
10
- class EventParser
11
-
12
- # Parse a raw string and return an object based on the event type.
13
- #
14
- # E.g. a raw string like:
15
- # > '["test","spec/reader_spec.rb",[],"spec/reader_spec.rb.log",3]'
16
- def parse(line)
17
- raw = JSON.load line
18
- event_from_data raw
19
- end
20
-
21
- protected
22
- # Create an event object from the array of data.
23
- def event_from_data(data)
24
- case data.first
25
- when 'test'
26
- TestEvent.new(*data)
27
- when /^(pass|fail)$/
28
- PassOrFailEvent.new(*data)
29
- when /^(pass_now_fail|fail_now_pass)$/
30
- StatusChangeEvent.new(data[0], data[1], event_from_data(data[2]))
31
- else
32
- Event.new(*data)
33
- end
34
- end
35
- end
36
- end
@@ -1,62 +0,0 @@
1
- require 'set'
2
-
3
- module Torkify
4
- # Wrapper around a Set class, that adds a dispatch method.
5
- #
6
- # Dispatch sends an event that calls a method on all observers.
7
- class ObserverSet
8
- def initialize(set = Set.new)
9
- @set = set
10
- end
11
-
12
- # Call a method on all observers, depending on the event type.
13
- #
14
- # The method is the event type prefixed with "on_". E.g. 'test' would be
15
- # 'on_test'.
16
- def dispatch(event)
17
- Torkify.logger.debug event.to_s
18
- @set.each do |observer|
19
- dispatch_each observer, event.message, event
20
- end
21
- end
22
-
23
- # Don't return a Set, return an ObserverSet.
24
- def |(enum)
25
- self.class.new(@set | enum)
26
- end
27
-
28
- def method_missing(method, *args, &blk)
29
- @set.send method, *args, &blk
30
- end
31
-
32
- def respond_to?(name, include_private = false)
33
- @set.respond_to? name, include_private
34
- end
35
-
36
- alias :+ :|
37
- alias :union :|
38
-
39
- private
40
- # Send the messages to a given observer, with the event object.
41
- def dispatch_each(observer, message, event)
42
- method = observer.method(message)
43
- observer.send message, *method_args(method, event)
44
- rescue NameError
45
- Torkify.logger.warn { "No method #{message} defined on #{observer.inspect}" }
46
- rescue => e
47
- Torkify.logger.error { "Caught exception from #{observer} during ##{message}: #{e}" }
48
- end
49
-
50
- # Determine whether to include the event in the arguments.
51
- #
52
- # The arity of the obsever's method is checked to see whether an
53
- # argument is received or not.
54
- def method_args(method, event)
55
- dispatch_args = []
56
- unless method.arity === 0
57
- dispatch_args << event
58
- end
59
- dispatch_args
60
- end
61
- end
62
- end
@@ -1,154 +0,0 @@
1
- require 'spec_helper'
2
- require 'torkify/event_parser'
3
-
4
- module Torkify
5
- describe EventParser do
6
- before { @parser = EventParser.new }
7
-
8
- context "when calling parse on a test event line with no numbers" do
9
- before do
10
- line = '["test","spec/reader_spec.rb",[],"spec/reader_spec.rb.log",3]'
11
- @event = @parser.parse line
12
- end
13
-
14
- subject { @event }
15
-
16
- it { should be_a TestEvent }
17
-
18
- its(:file) { should == 'spec/reader_spec.rb' }
19
- its(:lines) { should == [] }
20
- its(:log_file) { should == 'spec/reader_spec.rb.log' }
21
- its(:worker) { should == 3 }
22
- end
23
-
24
- context "when calling parse on a test event line with numbers" do
25
- before do
26
- line = '["test","spec/another_spec.rb",[20, 32, 41],"spec/another_spec.rb.log",6]'
27
- @event = @parser.parse line
28
- end
29
-
30
- subject { @event }
31
-
32
- it { should be_a TestEvent }
33
-
34
- its(:file) { should == 'spec/another_spec.rb' }
35
- its(:lines) { should == [20, 32, 41] }
36
- its(:log_file) { should == 'spec/another_spec.rb.log' }
37
- its(:worker) { should == 6 }
38
- end
39
-
40
- context "when calling parse on a pass event line" do
41
- before do
42
- line = '["pass","spec/pass_spec.rb",[27],"spec/pass_spec.rb.log",1,0,"#<Process::Status: pid 27490 exit 0>"]'
43
- @event = @parser.parse line
44
- end
45
-
46
- subject { @event }
47
-
48
- it { should be_a PassOrFailEvent }
49
- its(:type) { should == 'pass' }
50
- its(:file) { should == 'spec/pass_spec.rb' }
51
- its(:lines) { should == [27] }
52
- its(:log_file) { should == 'spec/pass_spec.rb.log' }
53
- its(:worker) { should == 1 }
54
- its(:exit_code) { should == 0 }
55
- its(:pid) { should == 27490 }
56
- end
57
-
58
- context "when calling parse on a fail event line" do
59
- before do
60
-
61
- line = '["fail","spec/fail_spec.rb",[],"spec/fail_spec.rb.log",1,256,"#<Process::Status: pid 23318 exit 1>"]'
62
- @event = @parser.parse line
63
- end
64
-
65
- subject { @event }
66
-
67
- it { should be_a PassOrFailEvent }
68
- its(:type) { should == 'fail' }
69
- its(:file) { should == 'spec/fail_spec.rb' }
70
- its(:lines) { should == [] }
71
- its(:log_file) { should == 'spec/fail_spec.rb.log' }
72
- its(:worker) { should == 1 }
73
- its(:exit_code) { should == 256 }
74
- its(:pid) { should == 23318 }
75
- end
76
-
77
- context "when calling parse on an absorb event line" do
78
- before do
79
- line = '["absorb"]'
80
- @event = @parser.parse line
81
- end
82
-
83
- subject { @event }
84
-
85
- it { should be_an Event }
86
- its(:type) { should == 'absorb' }
87
- end
88
-
89
- context "when calling parse on an unknown event type" do
90
- before do
91
- line = '["random"]'
92
- @event = @parser.parse line
93
- end
94
-
95
- subject { @event }
96
-
97
- it { should be_an Event }
98
- its(:type) { should == 'random' }
99
- end
100
-
101
- context "when calling parse on a pass now fail event line" do
102
- before do
103
- line = '["pass_now_fail","spec/status_change_spec.rb",["fail","spec/status_change_spec.rb",[68],"spec/status_change_spec.rb.log",2,256,"#<Process::Status: pid 23819 exit 1>"]]'
104
- @event = @parser.parse line
105
- end
106
-
107
- subject { @event }
108
-
109
- it { should be_a StatusChangeEvent }
110
- its(:type) { should == 'pass_now_fail' }
111
- its(:file) { should == 'spec/status_change_spec.rb' }
112
- its(:event) { should be_a PassOrFailEvent }
113
-
114
- context "and getting the inner event" do
115
- subject { @event.event }
116
-
117
- its(:type) { should == 'fail' }
118
- its(:file) { should == 'spec/status_change_spec.rb' }
119
- its(:log_file) { should == 'spec/status_change_spec.rb.log' }
120
- its(:lines) { should == [68] }
121
- its(:worker) { should == 2 }
122
- its(:exit_code) { should == 256 }
123
- its(:pid) { should == 23819 }
124
- end
125
- end
126
-
127
- context "when calling parse on a fail now pass event line" do
128
- before do
129
- line = '["fail_now_pass","spec/status_change_spec.rb",["pass","spec/status_change_spec.rb",[],"spec/status_change_spec.rb.log",1,0,"#<Process::Status: pid 677 exit 0>"]]'
130
- @event = @parser.parse line
131
- end
132
-
133
- subject { @event }
134
-
135
- it { should be_a StatusChangeEvent }
136
- its(:type) { should == 'fail_now_pass' }
137
- its(:file) { should == 'spec/status_change_spec.rb' }
138
- its(:event) { should be_a PassOrFailEvent }
139
-
140
- context "and getting the inner event" do
141
- subject { @event.event }
142
-
143
- its(:type) { should == 'pass' }
144
- its(:file) { should == 'spec/status_change_spec.rb' }
145
- its(:log_file) { should == 'spec/status_change_spec.rb.log' }
146
- its(:lines) { should == [] }
147
- its(:worker) { should == 1 }
148
- its(:exit_code) { should == 0 }
149
- its(:pid) { should == 677 }
150
- end
151
- end
152
-
153
- end
154
- end
data/spec/event_spec.rb DELETED
@@ -1,18 +0,0 @@
1
- require 'spec_helper'
2
- require 'torkify/events/event'
3
-
4
- module Torkify
5
- describe Event do
6
- context "when type is absorb" do
7
- before do
8
- @event = Event.new('absorb')
9
- end
10
-
11
- subject { @event }
12
-
13
- its(:type) { should == 'absorb' }
14
- its(:to_s) { should == 'absorb' }
15
- its(:message) { should == :on_absorb }
16
- end
17
- end
18
- end
@@ -1,100 +0,0 @@
1
- require 'spec_helper'
2
- require 'torkify/observer_set'
3
- require 'torkify/events/test_event'
4
- require 'torkify/events/pass_or_fail_event'
5
-
6
- module Torkify
7
- describe ObserverSet do
8
- before { @set = ObserverSet.new }
9
- subject { @set }
10
-
11
- it { should respond_to :length }
12
- it { should respond_to :add }
13
- it { should respond_to :<< }
14
- it { should respond_to :| }
15
-
16
- context "when empty" do
17
- its(:length) { should == 0 }
18
- end
19
-
20
- context "when calling union with an array" do
21
- before { @set |= [1, 3] }
22
-
23
- it { should be_a ObserverSet }
24
- its(:length) { should == 2 }
25
- its(:to_a) { should == [1, 3] }
26
- end
27
-
28
- context "when adding an array" do
29
- before { @set += [1, 3, 10] }
30
-
31
- it { should be_a ObserverSet }
32
- its(:length) { should == 3 }
33
- end
34
-
35
- context "when it contains one observer" do
36
- before do
37
- @observer = Object.new
38
- @set.add @observer
39
- end
40
-
41
- its(:length) { should == 1 }
42
-
43
- context "with a pass event" do
44
- before { @event = Torkify::PassOrFailEvent.new 'pass', 1, [], 3, 4, 5, 6 }
45
- it "should call the pass method on the observer with dispatch" do
46
- @observer.should_receive(:on_pass).with(@event)
47
- @set.dispatch(@event)
48
- end
49
- end
50
-
51
- context "with a fail event" do
52
- before do
53
- @event = Torkify::PassOrFailEvent.new 'fail', 1, [], 3, 4, 5, 6
54
- end
55
-
56
- it "should call the fail method on the observer with dispatch" do
57
- @observer.should_receive(:on_fail).with(@event)
58
- @set.dispatch(@event)
59
- end
60
-
61
- it "should not raise an error on dispatch with unknown method" do
62
- expect { @set.dispatch(@event) }.not_to raise_error
63
- end
64
-
65
- it "should not raise an error on dispatch to method with wrong number of parameters" do
66
- def @observer.on_fail; end
67
- expect { @set.dispatch(@event) }.not_to raise_error
68
- end
69
-
70
- it "should not raise an error on dispatch to method that raises an exception" do
71
- @observer.should_receive(:on_fail).and_raise(RuntimeError)
72
- expect { @set.dispatch(@event) }.not_to raise_error
73
- end
74
- end
75
- end
76
-
77
- context "when it contains multiple observers" do
78
- before { @set += [double, double, double] }
79
-
80
- its(:length) { should == 3 }
81
-
82
- it "should call the pass method on every observer with dispatch" do
83
- event = Torkify::PassOrFailEvent.new 'pass', 1, [], 3, 4, 5, 6
84
- @set.each { |o| o.should_receive(:on_pass).with(event) }
85
- @set.dispatch(event)
86
- end
87
-
88
- end
89
-
90
- context "when trying to add the same object twice" do
91
- before do
92
- object = double
93
- @set.add object
94
- @set.add object
95
- end
96
-
97
- its(:length) { should == 1 }
98
- end
99
- end
100
- end