rspec-activejob 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/Gemfile.lock +20 -18
- data/README.md +7 -3
- data/lib/rspec/active_job.rb +5 -0
- data/lib/rspec/active_job/deserialize_as.rb +29 -0
- data/lib/rspec/active_job/version.rb +1 -1
- data/rspec-activejob.gemspec +3 -1
- data/spec/rspec/active_job/deserialize_as_spec.rb +59 -0
- metadata +20 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ed4f20a431ed47d9bac346276c28f5c66143cf5
|
4
|
+
data.tar.gz: 2ac30436e51224415b3a083acbfb008eeaf7a1c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41552e56407232b5f260b1b8459725916a86b3b5411938bf87a23074f84f62bf58c011195952fac04dad56519bbe3970c06d98bd7c01c7ad9a8ad92135b870f5
|
7
|
+
data.tar.gz: f057e07d01d62994ec8d586f56af964075bafe140c95c3843a29913eb79d46b01f37f2cfd90b984641f133a106042625cc02ba09e806ff42c0a894062bdb7cd9
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
## 0.3.0 - Unreleased
|
2
|
+
|
3
|
+
- Added the `deserialize_as` matcher
|
4
|
+
|
5
|
+
## 0.2.0 - January 21, 2015
|
6
|
+
|
7
|
+
- Added the `global_id` matcher
|
8
|
+
|
1
9
|
## 0.1.0 - January 18, 2015
|
2
10
|
|
3
11
|
- Added support for argument matchers (e.g. `instance_of`, `hash_including`), like the `receive` matcher.
|
data/Gemfile.lock
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
rspec-activejob (0.
|
4
|
+
rspec-activejob (0.3.0)
|
5
5
|
activejob (>= 4.2)
|
6
6
|
rspec-mocks
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activejob (4.2.
|
12
|
-
activesupport (= 4.2.
|
11
|
+
activejob (4.2.1)
|
12
|
+
activesupport (= 4.2.1)
|
13
13
|
globalid (>= 0.3.0)
|
14
|
-
activesupport (4.2.
|
14
|
+
activesupport (4.2.1)
|
15
15
|
i18n (~> 0.7)
|
16
16
|
json (~> 1.7, >= 1.7.7)
|
17
17
|
minitest (~> 5.1)
|
@@ -19,7 +19,7 @@ GEM
|
|
19
19
|
tzinfo (~> 1.1)
|
20
20
|
coderay (1.1.0)
|
21
21
|
diff-lcs (1.2.5)
|
22
|
-
globalid (0.3.
|
22
|
+
globalid (0.3.3)
|
23
23
|
activesupport (>= 4.1.0)
|
24
24
|
i18n (0.7.0)
|
25
25
|
json (1.8.2)
|
@@ -29,23 +29,24 @@ GEM
|
|
29
29
|
coderay (~> 1.1.0)
|
30
30
|
method_source (~> 0.8.1)
|
31
31
|
slop (~> 3.4)
|
32
|
-
rspec (3.
|
33
|
-
rspec-core (~> 3.
|
34
|
-
rspec-expectations (~> 3.
|
35
|
-
rspec-mocks (~> 3.
|
36
|
-
rspec-core (3.
|
37
|
-
rspec-support (~> 3.
|
38
|
-
rspec-expectations (3.
|
32
|
+
rspec (3.2.0)
|
33
|
+
rspec-core (~> 3.2.0)
|
34
|
+
rspec-expectations (~> 3.2.0)
|
35
|
+
rspec-mocks (~> 3.2.0)
|
36
|
+
rspec-core (3.2.2)
|
37
|
+
rspec-support (~> 3.2.0)
|
38
|
+
rspec-expectations (3.2.0)
|
39
39
|
diff-lcs (>= 1.2.0, < 2.0)
|
40
|
-
rspec-support (~> 3.
|
41
|
-
rspec-its (1.
|
40
|
+
rspec-support (~> 3.2.0)
|
41
|
+
rspec-its (1.2.0)
|
42
42
|
rspec-core (>= 3.0.0)
|
43
43
|
rspec-expectations (>= 3.0.0)
|
44
|
-
rspec-mocks (3.1
|
45
|
-
|
46
|
-
|
44
|
+
rspec-mocks (3.2.1)
|
45
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
46
|
+
rspec-support (~> 3.2.0)
|
47
|
+
rspec-support (3.2.2)
|
47
48
|
slop (3.6.0)
|
48
|
-
thread_safe (0.3.
|
49
|
+
thread_safe (0.3.5)
|
49
50
|
tzinfo (1.2.2)
|
50
51
|
thread_safe (~> 0.1)
|
51
52
|
|
@@ -53,6 +54,7 @@ PLATFORMS
|
|
53
54
|
ruby
|
54
55
|
|
55
56
|
DEPENDENCIES
|
57
|
+
activesupport
|
56
58
|
pry
|
57
59
|
rspec
|
58
60
|
rspec-activejob!
|
data/README.md
CHANGED
@@ -5,6 +5,8 @@
|
|
5
5
|
config.active_job.queue_adapter = :test
|
6
6
|
|
7
7
|
# spec/spec_helper.rb
|
8
|
+
require 'rspec/active_job'
|
9
|
+
|
8
10
|
RSpec.configure do |config|
|
9
11
|
config.include(RSpec::ActiveJob)
|
10
12
|
|
@@ -27,10 +29,10 @@ end
|
|
27
29
|
|
28
30
|
rspec-activejob expects the current queue adapter to expose an array of `enqueued_jobs`, like the included
|
29
31
|
test adapter. The test adapter included in ActiveJob 4.2.0 does not fully serialize its arguments, so you
|
30
|
-
will not need to use the GlobalID matcher
|
31
|
-
test adapter.
|
32
|
+
will not need to use the GlobalID matcher unless you're using ActiveJob 4.2.1. See rails/rails#18266 for
|
33
|
+
the improved test adapter.
|
32
34
|
|
33
|
-
This gem defines
|
35
|
+
This gem defines three matchers:
|
34
36
|
|
35
37
|
* `enqueue_a`: for a block or proc, expects that to enqueue an job to the ActiveJob test adapter. Optionally
|
36
38
|
takes the job class as its argument, and can be modified with a `.with(*args)` call to expect specific arguments.
|
@@ -41,6 +43,8 @@ This gem defines two matchers:
|
|
41
43
|
the serialized version of any instance of that model; if you pass an instance, it will expect the serialized
|
42
44
|
version of that specific instance.
|
43
45
|
|
46
|
+
* `deserialize_as(hash)`: an argument matcher, matching ActiveJob-serialized versions of hashes (with
|
47
|
+
string/symbol keys, or with indifferent access).
|
44
48
|
|
45
49
|
With the `global_id` matcher it's important to note that it's specific to ActiveJob-serialized GlobalIDs.
|
46
50
|
ActiveJob serializes them as a hash like `{ '_aj_global_id' => 'gid://my-app/MyModel/ID123' }`, to avoid
|
data/lib/rspec/active_job.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'rspec/active_job/enqueue_a'
|
2
2
|
require 'rspec/active_job/global_id'
|
3
|
+
require 'rspec/active_job/deserialize_as'
|
3
4
|
|
4
5
|
module RSpec
|
5
6
|
module ActiveJob
|
@@ -10,5 +11,9 @@ module RSpec
|
|
10
11
|
def global_id(expected)
|
11
12
|
Matchers::GlobalID.new(expected)
|
12
13
|
end
|
14
|
+
|
15
|
+
def deserialize_as(expected)
|
16
|
+
Matchers::DeserializeAs.new(expected)
|
17
|
+
end
|
13
18
|
end
|
14
19
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'active_job/arguments'
|
2
|
+
require 'active_support/core_ext/hash/indifferent_access'
|
3
|
+
|
4
|
+
module RSpec
|
5
|
+
module ActiveJob
|
6
|
+
module Matchers
|
7
|
+
class DeserializeAs
|
8
|
+
def initialize(expected)
|
9
|
+
@expected = expected
|
10
|
+
end
|
11
|
+
|
12
|
+
def ===(other)
|
13
|
+
deserialize(other).class == @expected.class &&
|
14
|
+
deserialize(other) == @expected
|
15
|
+
end
|
16
|
+
|
17
|
+
def description
|
18
|
+
"an object deserializing to #{@expected}"
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def deserialize(argument)
|
24
|
+
::ActiveJob::Arguments.deserialize([argument]).first
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/rspec-activejob.gemspec
CHANGED
@@ -9,7 +9,8 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.summary = 'RSpec matchers to test ActiveJob'
|
10
10
|
s.description = <<-EOL
|
11
11
|
RSpec matchers for ActiveJob:
|
12
|
-
* expect { method }.to enqueue_a(MyJob).with(
|
12
|
+
* expect { method }.to enqueue_a(MyJob).with(global_id(some_model),
|
13
|
+
deserialize_as(other_argument))
|
13
14
|
EOL
|
14
15
|
s.homepage = 'http://github.com/gocardless/rspec-activejob'
|
15
16
|
s.license = 'MIT'
|
@@ -23,4 +24,5 @@ Gem::Specification.new do |s|
|
|
23
24
|
|
24
25
|
s.add_development_dependency('rspec')
|
25
26
|
s.add_development_dependency('rspec-its')
|
27
|
+
s.add_development_dependency('activesupport')
|
26
28
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe RSpec::ActiveJob::Matchers::DeserializeAs do
|
4
|
+
let(:instance) { described_class.new(expected) }
|
5
|
+
subject(:matches?) { instance === actual }
|
6
|
+
|
7
|
+
context "with an indifferent hash" do
|
8
|
+
let(:actual) do
|
9
|
+
{ 'key' => 'value', '_aj_hash_with_indifferent_access' => true }
|
10
|
+
end
|
11
|
+
let(:expected) { ActiveSupport::HashWithIndifferentAccess.new(key: 'value') }
|
12
|
+
|
13
|
+
it { is_expected.to be(true) }
|
14
|
+
|
15
|
+
context "with a non-indifferent hash serialized" do
|
16
|
+
let(:actual) { { 'key' => 'value', '_aj_symbol_keys' => [] } }
|
17
|
+
|
18
|
+
it { is_expected.to be(false) }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "with a string-keyed hash" do
|
23
|
+
let(:expected) { { 'key' => 'value' } }
|
24
|
+
let(:actual) { { 'key' => 'value', '_aj_symbol_keys' => [] } }
|
25
|
+
|
26
|
+
it { is_expected.to be(true) }
|
27
|
+
|
28
|
+
context "with an indifferent hash serialized" do
|
29
|
+
let(:actual) do
|
30
|
+
{ 'key' => 'value', '_aj_hash_with_indifferent_access' => true }
|
31
|
+
end
|
32
|
+
it { is_expected.to be(false) }
|
33
|
+
end
|
34
|
+
|
35
|
+
context "with a symbol keyed hash serialized" do
|
36
|
+
let(:actual) { { 'key' => 'value', '_aj_symbol_keys' => ['key'] } }
|
37
|
+
it { is_expected.to be(false) }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "with a symbol-keyed hash" do
|
42
|
+
let(:expected) { { key: 'value' } }
|
43
|
+
let(:actual) { { 'key' => 'value', '_aj_symbol_keys' => ['key'] } }
|
44
|
+
|
45
|
+
it { is_expected.to be(true) }
|
46
|
+
|
47
|
+
context "with an indifferent hash serialized" do
|
48
|
+
let(:actual) do
|
49
|
+
{ 'key' => 'value', '_aj_hash_with_indifferent_access' => true }
|
50
|
+
end
|
51
|
+
it { is_expected.to be(false) }
|
52
|
+
end
|
53
|
+
|
54
|
+
context "with a string keyed hash serialized" do
|
55
|
+
let(:actual) { { 'key' => 'value', '_aj_symbol_keys' => [] } }
|
56
|
+
it { is_expected.to be(false) }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-activejob
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Isaac Seymour
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activejob
|
@@ -66,9 +66,24 @@ dependencies:
|
|
66
66
|
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activesupport
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
description: |2
|
70
84
|
RSpec matchers for ActiveJob:
|
71
|
-
* expect { method }.to enqueue_a(MyJob).with(
|
85
|
+
* expect { method }.to enqueue_a(MyJob).with(global_id(some_model),
|
86
|
+
deserialize_as(other_argument))
|
72
87
|
email:
|
73
88
|
- isaac@isaacseymour.co.uk
|
74
89
|
executables: []
|
@@ -82,10 +97,12 @@ files:
|
|
82
97
|
- Gemfile.lock
|
83
98
|
- README.md
|
84
99
|
- lib/rspec/active_job.rb
|
100
|
+
- lib/rspec/active_job/deserialize_as.rb
|
85
101
|
- lib/rspec/active_job/enqueue_a.rb
|
86
102
|
- lib/rspec/active_job/global_id.rb
|
87
103
|
- lib/rspec/active_job/version.rb
|
88
104
|
- rspec-activejob.gemspec
|
105
|
+
- spec/rspec/active_job/deserialize_as_spec.rb
|
89
106
|
- spec/rspec/active_job/enqueue_a_spec.rb
|
90
107
|
- spec/rspec/active_job/global_id_spec.rb
|
91
108
|
- spec/spec_helper.rb
|