rx-rspec 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 17fca61b862bdad691dada39e00c9783ea63b64e
4
- data.tar.gz: b3aafdb9e48e4a880e42612b9c1692b05155db64
3
+ metadata.gz: ea42b945e59e9144d939237c9388170601eb97c8
4
+ data.tar.gz: a92e9dffc00ac1d9f9ff15b10defa294d4cc9f22
5
5
  SHA512:
6
- metadata.gz: c135aab0a3ef97412faede7313f34d6c3bb4ba6fad7e404226ad8e2f70811373d166e74ce521c286459e03b6c8f3479d034b294a27b34da7fb7cdbb0eb7fccef
7
- data.tar.gz: c0d4d32b06750f2359fda10308039c03836fda0116e14c6442ddddaec1a8449265f3b9668046960b92775adffa7cced8d73734bd677128217258dd342c39f4fa
6
+ metadata.gz: 224d617fa86f43db7611cb5bf5eb94e7bb6503acb3f5d1a50ab55401f13f0687da030800af328e5b3a92793ade520a33c5ea19c64678a9d80ea134021f36da7b
7
+ data.tar.gz: afc76bd47831a7f388a4a9d4d0f59c01a5a5db5481dd15985f5a13a9e883e89b9acbb20c8841bd994bb2b45790c06bf0dbd98a0d9f317ffe6a9ad3939eabbaad
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rx-rspec (0.2.0)
4
+ rx-rspec (0.3.0)
5
5
  rx
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -13,7 +13,7 @@ The asynchronous nature of RxRuby makes it hard to write good specs for code tha
13
13
 
14
14
  The goal of rx-rspec is to provide powerful matchers that lets you express your expectations in a traditional rspec-like synchronous manner.
15
15
 
16
- Currently, the ambition of this project is simply to support the use cases that I encounter in my own usage of RxRuby. Your pull requests are wellcome.
16
+ Currently, the ambition of this project is simply to support the use cases that I encounter in my own usage of RxRuby. Your pull requests are welcome.
17
17
 
18
18
  ## Usage
19
19
 
@@ -37,6 +37,7 @@ end
37
37
 
38
38
  rx-spec include the following matchers:
39
39
 
40
- - **emit_exactly()** metches against all items produced by the observable and requires the observable to be completed.
40
+ - **emit_nothing()** matches an observable that completes without emitting events or erroring.
41
+ - **emit_exactly()** matches against all items produced by the observable and requires the observable to be completed.
41
42
  - **emit_first()** matches against the first elements of the observable, but does not require it to complete
42
43
  - **emit_include()** consumes elements until the expected elements have occurred
@@ -1,9 +1,12 @@
1
1
  require 'rspec'
2
+ require 'rx-rspec/shared'
2
3
 
3
4
  # TODO:
4
5
  # - should have specific timeout message 'x seconds waiting for y'
5
6
 
6
7
  RSpec::Matchers.define :emit_exactly do |*expected|
8
+ include RxRspec::Shared
9
+
7
10
  events = []
8
11
  errors = []
9
12
  match do |actual|
@@ -28,14 +31,17 @@ RSpec::Matchers.define :emit_exactly do |*expected|
28
31
  end.join
29
32
 
30
33
  return false unless errors.empty?
34
+ @actual = events
31
35
  values_match? expected, events
32
36
  end
33
37
 
38
+ diffable
39
+
34
40
  failure_message do
35
41
  if errors.empty?
36
42
  "expected #{events} to match #{expected}"
37
43
  else
38
- "expected #{expected} but received error #{errors[0].inspect}"
44
+ present_error(expected, errors[0])
39
45
  end
40
46
  end
41
47
  end
@@ -1,9 +1,12 @@
1
1
  require 'rspec'
2
+ require 'rx-rspec/shared'
2
3
 
3
4
  # TODO:
4
5
  # - should have specific timeout message 'x seconds waiting for y'
5
6
 
6
7
  RSpec::Matchers.define :emit_first do |*expected|
8
+ include RxRspec::Shared
9
+
7
10
  events = []
8
11
  errors = []
9
12
  completed = []
@@ -37,7 +40,7 @@ RSpec::Matchers.define :emit_first do |*expected|
37
40
  if errors.empty?
38
41
  "expected #{events} to emit at least #{expected}"
39
42
  else
40
- "expected #{expected} but received error #{errors[0].inspect}"
43
+ present_error(expected, errors[0])
41
44
  end
42
45
  end
43
46
  end
@@ -1,9 +1,12 @@
1
1
  require 'rspec'
2
+ require 'rx-rspec/shared'
2
3
 
3
4
  # TODO:
4
5
  # - should have specific timeout message 'x seconds waiting for y'
5
6
 
6
7
  RSpec::Matchers.define :emit_include do |*expected|
8
+ include RxRspec::Shared
9
+
7
10
  events = []
8
11
  errors = []
9
12
  completed = []
@@ -38,7 +41,7 @@ RSpec::Matchers.define :emit_include do |*expected|
38
41
  if errors.empty?
39
42
  "expected #{events} to include #{expected}"
40
43
  else
41
- "expected #{expected} but received error #{errors[0].inspect}"
44
+ present_error(expected, errors[0])
42
45
  end
43
46
  end
44
47
  end
@@ -0,0 +1,39 @@
1
+ require 'rspec'
2
+ require 'rx-rspec/shared'
3
+
4
+ # TODO:
5
+ # - should have specific timeout message 'x seconds waiting for y'
6
+
7
+ RSpec::Matchers.define :emit_nothing do |*expected|
8
+ include RxRspec::Shared
9
+
10
+ events = []
11
+ errors = []
12
+ completed = []
13
+ match do |actual|
14
+ Thread.new do
15
+ actual.subscribe(
16
+ lambda { |event| events << event },
17
+ lambda { |err| errors << err },
18
+ lambda { completed << :complete }
19
+ )
20
+ for n in 1..10
21
+ break unless completed.empty?
22
+ break unless errors.empty? && events.empty?
23
+ sleep(0.05)
24
+ end
25
+ raise 'timeout' if errors.empty? && events.empty? && completed.empty?
26
+ end.join
27
+
28
+ return false unless errors.empty?
29
+ return events.empty?
30
+ end
31
+
32
+ failure_message do
33
+ if errors.empty?
34
+ "unexpected #{events[0]} emitted"
35
+ else
36
+ present_error(expected, errors[0])
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,9 @@
1
+ module RxRspec
2
+ module Shared
3
+ def present_error(expected, error)
4
+ backtrace = error.backtrace || []
5
+ present_error = "#{error.inspect}:#{$/}#{backtrace.join($/)}"
6
+ "expected #{expected} but received error #{present_error}"
7
+ end
8
+ end
9
+ 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.2.0'
3
+ spec.version = '0.3.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,97 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rx-rspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.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-16 00:00:00.000000000 Z
11
+ date: 2017-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rx
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.13'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.13'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: byebug
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
61
  version: '3.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ~>
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: simplecov
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - '>='
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: codeclimate-test-reporter
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - '>='
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  description: Writing specs for reactive streams is tricky both because of their asynchronous
@@ -103,8 +103,8 @@ executables: []
103
103
  extensions: []
104
104
  extra_rdoc_files: []
105
105
  files:
106
- - ".gitignore"
107
- - ".travis.yml"
106
+ - .gitignore
107
+ - .travis.yml
108
108
  - Gemfile
109
109
  - Gemfile.lock
110
110
  - LICENSE.md
@@ -113,6 +113,8 @@ files:
113
113
  - lib/rx-rspec/exactly.rb
114
114
  - lib/rx-rspec/first.rb
115
115
  - lib/rx-rspec/include.rb
116
+ - lib/rx-rspec/nothing.rb
117
+ - lib/rx-rspec/shared.rb
116
118
  - rx-rspec.gemspec
117
119
  homepage: http://github.org/bittrance/rx-rspec
118
120
  licenses:
@@ -124,17 +126,17 @@ require_paths:
124
126
  - lib
125
127
  required_ruby_version: !ruby/object:Gem::Requirement
126
128
  requirements:
127
- - - ">="
129
+ - - '>='
128
130
  - !ruby/object:Gem::Version
129
131
  version: 2.0.0
130
132
  required_rubygems_version: !ruby/object:Gem::Requirement
131
133
  requirements:
132
- - - ">="
134
+ - - '>='
133
135
  - !ruby/object:Gem::Version
134
136
  version: '0'
135
137
  requirements: []
136
138
  rubyforge_project:
137
- rubygems_version: 2.4.5.1
139
+ rubygems_version: 2.0.14.1
138
140
  signing_key:
139
141
  specification_version: 4
140
142
  summary: rspec testing support for RxRuby