rx-rspec 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/.travis.yml +6 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +37 -0
- data/README.md +29 -0
- data/lib/rx-rspec/matchers.rb +53 -0
- data/rx-rspec.gemspec +21 -0
- metadata +108 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7b36a682d9edba3b5f7b8811178782c4492cf765
|
4
|
+
data.tar.gz: 5317201f7b99a18bcdaedb4aa112e327e50ae76c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 222a02a74a8e05e81c2c292dde52e3ff32305952afe57199824ba94df2e70ee6ad36dab36e95ea873a7f4a3cb8d90a31b154e0051c4d8287ed14c8eb18d28c4e
|
7
|
+
data.tar.gz: 1dffb8bb92400eea6db2fa3ccff0cf2c83e79c90fbb82d8c8814b53355a23e08ea6ceb9c6e5af1d2598eda2ceea925c40aa0142ba3f2fcf3275a802d745527da
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rx-rspec (0.1.0)
|
5
|
+
rx
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
byebug (9.0.6)
|
11
|
+
diff-lcs (1.2.5)
|
12
|
+
rspec (3.5.0)
|
13
|
+
rspec-core (~> 3.5.0)
|
14
|
+
rspec-expectations (~> 3.5.0)
|
15
|
+
rspec-mocks (~> 3.5.0)
|
16
|
+
rspec-core (3.5.4)
|
17
|
+
rspec-support (~> 3.5.0)
|
18
|
+
rspec-expectations (3.5.0)
|
19
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
20
|
+
rspec-support (~> 3.5.0)
|
21
|
+
rspec-mocks (3.5.0)
|
22
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
23
|
+
rspec-support (~> 3.5.0)
|
24
|
+
rspec-support (3.5.0)
|
25
|
+
rx (0.0.3)
|
26
|
+
|
27
|
+
PLATFORMS
|
28
|
+
ruby
|
29
|
+
|
30
|
+
DEPENDENCIES
|
31
|
+
bundler (~> 1.13)
|
32
|
+
byebug
|
33
|
+
rspec (~> 3.0)
|
34
|
+
rx-rspec!
|
35
|
+
|
36
|
+
BUNDLED WITH
|
37
|
+
1.13.6
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Rspec matchers for RxRuby observables
|
2
|
+
|
3
|
+
## Rationale
|
4
|
+
|
5
|
+
The asynchronous nature of RxRuby makes it hard to write good specs for code that returns observables. The complexity of next/error/completed notifications can also easily trip up a naive spec.
|
6
|
+
|
7
|
+
## Goal
|
8
|
+
|
9
|
+
The goal of rx-rspec is to provide powerful matchers that lets you express your expectations in a traditional rspec-like synchronous manner.
|
10
|
+
|
11
|
+
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.
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
rx-rspec is available from http://rubygems.org:
|
16
|
+
```
|
17
|
+
gem install rx-rspec
|
18
|
+
```
|
19
|
+
|
20
|
+
Once installed, you can use it to assert on your observables:
|
21
|
+
```
|
22
|
+
require 'rx'
|
23
|
+
require 'rx-rspec'
|
24
|
+
|
25
|
+
describe 'awesome' do
|
26
|
+
subject { Rx::Observable.just(42) }
|
27
|
+
it { should emit_exactly(42) }
|
28
|
+
end
|
29
|
+
```
|
@@ -0,0 +1,53 @@
|
|
1
|
+
RSpec::Matchers.define :emit_exactly do |*expected|
|
2
|
+
events = []
|
3
|
+
errors = []
|
4
|
+
match do |actual|
|
5
|
+
Thread.new do
|
6
|
+
spinlock = expected.size
|
7
|
+
actual.subscribe(
|
8
|
+
lambda do |event|
|
9
|
+
events << event
|
10
|
+
spinlock -= 1
|
11
|
+
end,
|
12
|
+
lambda do |err|
|
13
|
+
errors << err
|
14
|
+
spinlock = 0
|
15
|
+
end,
|
16
|
+
lambda { spinlock = 0 }
|
17
|
+
)
|
18
|
+
for n in 1..10
|
19
|
+
break if spinlock == 0
|
20
|
+
sleep(0.05)
|
21
|
+
end
|
22
|
+
raise 'timeout' if spinlock > 0
|
23
|
+
end.join
|
24
|
+
|
25
|
+
return false unless errors.empty?
|
26
|
+
|
27
|
+
expected.zip(events).all? do |exp, evt|
|
28
|
+
if exp.respond_to?(:matches?)
|
29
|
+
exp.matches?(evt)
|
30
|
+
else
|
31
|
+
exp == evt
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
description do
|
37
|
+
if expected.size == 1
|
38
|
+
"emit #{expected}"
|
39
|
+
else
|
40
|
+
"emit exactly #{expected.size} items"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
failure_message do
|
45
|
+
if errors.empty?
|
46
|
+
"expected #{events} to match #{expected}"
|
47
|
+
else
|
48
|
+
"expected #{expected} but received error #{errors[0].inspect}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
diffable
|
53
|
+
end
|
data/rx-rspec.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = 'rx-rspec'
|
3
|
+
spec.version = '0.1.0'
|
4
|
+
spec.date = '2016-12-28'
|
5
|
+
spec.summary = 'rspec testing support for RxRuby'
|
6
|
+
spec.description = 'Writing specs for reactive streams is tricky both because of their asynchronous nature and because their semantics. This module provides various matchers that allows you to write ordinary-looking specs that assert on the nature of your observables.'
|
7
|
+
spec.authors = ['Anders Qvist']
|
8
|
+
spec.email = 'bittrance@gmail.com'
|
9
|
+
spec.homepage = 'http://rubygems.org/gems/rx-rspec'
|
10
|
+
spec.license = 'MIT'
|
11
|
+
|
12
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(/^spec/) }
|
13
|
+
|
14
|
+
spec.required_ruby_version = '>= 2.0.0'
|
15
|
+
|
16
|
+
spec.add_runtime_dependency 'rx'
|
17
|
+
|
18
|
+
spec.add_development_dependency 'bundler', '~> 1.13'
|
19
|
+
spec.add_development_dependency 'byebug'
|
20
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rx-rspec
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Anders Qvist
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rx
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.13'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.13'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: byebug
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description: Writing specs for reactive streams is tricky both because of their asynchronous
|
70
|
+
nature and because their semantics. This module provides various matchers that allows
|
71
|
+
you to write ordinary-looking specs that assert on the nature of your observables.
|
72
|
+
email: bittrance@gmail.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- .gitignore
|
78
|
+
- .travis.yml
|
79
|
+
- Gemfile
|
80
|
+
- Gemfile.lock
|
81
|
+
- README.md
|
82
|
+
- lib/rx-rspec/matchers.rb
|
83
|
+
- rx-rspec.gemspec
|
84
|
+
homepage: http://rubygems.org/gems/rx-rspec
|
85
|
+
licenses:
|
86
|
+
- MIT
|
87
|
+
metadata: {}
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 2.0.0
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 2.0.14.1
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: rspec testing support for RxRuby
|
108
|
+
test_files: []
|