rx-rspec 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4d04c7319d97b9aa65068cc6128a4d2f4981083c
4
- data.tar.gz: ad2c11c3cbbff7fddcaafa6b78095b0ef0d01163
3
+ metadata.gz: 17fca61b862bdad691dada39e00c9783ea63b64e
4
+ data.tar.gz: b3aafdb9e48e4a880e42612b9c1692b05155db64
5
5
  SHA512:
6
- metadata.gz: fd7053d1a53726b682e5ed047ded7a9e79429d7bfa1976e7f0c68458ec1b0ea3cb874954a2f8bfd9f0bf2922efe93319a4f76e1b7b9e105d3eb1f0cf211e21c8
7
- data.tar.gz: 60ffe9b2d84ae7291bc4379416b9f70df3bf12798592190548e4c1b5f27df1e9f8c1135738b24dacacaf2aa66d40eb408a6535ecc1c88df6821396b65449e7cd
6
+ metadata.gz: c135aab0a3ef97412faede7313f34d6c3bb4ba6fad7e404226ad8e2f70811373d166e74ce521c286459e03b6c8f3479d034b294a27b34da7fb7cdbb0eb7fccef
7
+ data.tar.gz: c0d4d32b06750f2359fda10308039c03836fda0116e14c6442ddddaec1a8449265f3b9668046960b92775adffa7cced8d73734bd677128217258dd342c39f4fa
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rx-rspec (0.1.3)
4
+ rx-rspec (0.2.0)
5
5
  rx
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -28,7 +28,15 @@ require 'rx'
28
28
  require 'rx-rspec'
29
29
 
30
30
  describe 'awesome' do
31
- subject { Rx::Observable.just(42) }
32
- it { should emit_exactly(42) }
31
+ subject { Rx::Observable.of(1, 2, 3) }
32
+ it { should emit_exactly(1, 2, 3) }
33
33
  end
34
34
  ```
35
+
36
+ ## Matchers
37
+
38
+ rx-spec include the following matchers:
39
+
40
+ - **emit_exactly()** metches against all items produced by the observable and requires the observable to be completed.
41
+ - **emit_first()** matches against the first elements of the observable, but does not require it to complete
42
+ - **emit_include()** consumes elements until the expected elements have occurred
data/lib/rx-rspec.rb CHANGED
@@ -1 +1,3 @@
1
- require 'rx-rspec/matchers'
1
+ require 'rx-rspec/exactly'
2
+ require 'rx-rspec/first'
3
+ require 'rx-rspec/include'
@@ -0,0 +1,41 @@
1
+ require 'rspec'
2
+
3
+ # TODO:
4
+ # - should have specific timeout message 'x seconds waiting for y'
5
+
6
+ RSpec::Matchers.define :emit_exactly do |*expected|
7
+ events = []
8
+ errors = []
9
+ match do |actual|
10
+ Thread.new do
11
+ spinlock = expected.size
12
+ actual.subscribe(
13
+ lambda do |event|
14
+ events << event
15
+ spinlock -= 1
16
+ end,
17
+ lambda do |err|
18
+ errors << err
19
+ spinlock = 0
20
+ end,
21
+ lambda { spinlock = 0 }
22
+ )
23
+ for n in 1..10
24
+ break if spinlock == 0
25
+ sleep(0.05)
26
+ end
27
+ raise 'timeout' if spinlock > 0
28
+ end.join
29
+
30
+ return false unless errors.empty?
31
+ values_match? expected, events
32
+ end
33
+
34
+ failure_message do
35
+ if errors.empty?
36
+ "expected #{events} to match #{expected}"
37
+ else
38
+ "expected #{expected} but received error #{errors[0].inspect}"
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,43 @@
1
+ require 'rspec'
2
+
3
+ # TODO:
4
+ # - should have specific timeout message 'x seconds waiting for y'
5
+
6
+ RSpec::Matchers.define :emit_first do |*expected|
7
+ events = []
8
+ errors = []
9
+ completed = []
10
+
11
+ match do |actual|
12
+ raise 'Please supply at least one expectation' if expected.size == 0
13
+ expect_clone = expected.dup
14
+ Thread.new do
15
+ deadline = Time.now + 0.5
16
+ actual.take_while do |event|
17
+ events << event
18
+ values_match?(expect_clone.shift, event) && expect_clone.size > 0
19
+ end.subscribe(
20
+ lambda { |event| },
21
+ lambda { |err| errors << err },
22
+ lambda { completed << :complete }
23
+ )
24
+
25
+ until Time.now > deadline
26
+ break if expect_clone.empty?
27
+ break unless completed.empty? && errors.empty?
28
+ sleep(0.05)
29
+ end
30
+ raise 'timeout' if Time.now > deadline
31
+ end.join
32
+
33
+ expect_clone.empty?
34
+ end
35
+
36
+ failure_message do
37
+ if errors.empty?
38
+ "expected #{events} to emit at least #{expected}"
39
+ else
40
+ "expected #{expected} but received error #{errors[0].inspect}"
41
+ end
42
+ end
43
+ end
@@ -42,40 +42,3 @@ RSpec::Matchers.define :emit_include do |*expected|
42
42
  end
43
43
  end
44
44
  end
45
-
46
- RSpec::Matchers.define :emit_exactly do |*expected|
47
- events = []
48
- errors = []
49
- match do |actual|
50
- Thread.new do
51
- spinlock = expected.size
52
- actual.subscribe(
53
- lambda do |event|
54
- events << event
55
- spinlock -= 1
56
- end,
57
- lambda do |err|
58
- errors << err
59
- spinlock = 0
60
- end,
61
- lambda { spinlock = 0 }
62
- )
63
- for n in 1..10
64
- break if spinlock == 0
65
- sleep(0.05)
66
- end
67
- raise 'timeout' if spinlock > 0
68
- end.join
69
-
70
- return false unless errors.empty?
71
- values_match? expected, events
72
- end
73
-
74
- failure_message do
75
- if errors.empty?
76
- "expected #{events} to match #{expected}"
77
- else
78
- "expected #{expected} but received error #{errors[0].inspect}"
79
- end
80
- end
81
- end
data/rx-rspec.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'rx-rspec'
3
- spec.version = '0.1.3'
3
+ spec.version = '0.2.0'
4
4
  spec.summary = 'rspec testing support for RxRuby'
5
5
  spec.description = 'Writing specs for reactive streams is tricky both because of their asynchronous nature and because their next/error/completed semantics. The goal of rx-rspec is to provide powerful matchers that lets you express your expectations in a traditional rspec-like synchronous manner.'
6
6
  spec.authors = ['Anders Qvist']
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rx-rspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anders Qvist
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-05 00:00:00.000000000 Z
11
+ date: 2017-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rx
@@ -110,7 +110,9 @@ files:
110
110
  - LICENSE.md
111
111
  - README.md
112
112
  - lib/rx-rspec.rb
113
- - lib/rx-rspec/matchers.rb
113
+ - lib/rx-rspec/exactly.rb
114
+ - lib/rx-rspec/first.rb
115
+ - lib/rx-rspec/include.rb
114
116
  - rx-rspec.gemspec
115
117
  homepage: http://github.org/bittrance/rx-rspec
116
118
  licenses: