rspec-activejob 0.4.2 → 0.5.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: 88c1648df6c71008bec37d636f453239f8b32528
4
- data.tar.gz: 7007b7ad633537d0a2e7d2e0e6842db92babf40b
3
+ metadata.gz: 67fc94e6b07a0f9566fa7fc4687563affa38629a
4
+ data.tar.gz: 5650bb54c6add28bd7b7ae830e3fec9d2a7ae925
5
5
  SHA512:
6
- metadata.gz: 752a896cd5bb286546514d5d96f2277877e98238a6979f4540c8787be59b6ea3ce7476b2c8df4d16ece2086c3cf53cf21d301972e74a19418c91042e5018423a
7
- data.tar.gz: 8a8712194227772f71ebc15be8a82bf33356333949b64930b3572088920202884d3423eb3e75e55ef989e1fb248c2e3cbb833079961cef28e5df92bad1999fa2
6
+ metadata.gz: 32f2e4850d9ce2f45f6639d1a656a4045f91d1158a1a822b3686ed588e4219c491489fc27900bd0dff99e02dfa0dd83bd6299ff18757d7172af0a3c14a81d03b
7
+ data.tar.gz: 50c75b3434f3033d92129f09e99d2b09346c45444f33348f97a816a00303ee8f6a2b3fa430e86523fd8ad4fea0acc73b811fd871e1fa5e7c3204350968b79e3f
@@ -1,5 +1,3 @@
1
- inherit_from: .rubocop_todo.yml
2
-
3
1
  # Limit lines to 90 characters.
4
2
  LineLength:
5
3
  Max: 90
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2
4
+ - 2.1
5
+ - 2.0
6
+ - 1.9
7
+ - jruby-19mode
8
+ script:
9
+ - bundle exec rspec
10
+ - bundle exec rubocop
@@ -1,3 +1,7 @@
1
+ ## 0.5.0 - September 16, 2015
2
+
3
+ - Add `to_run_at` modifier - patch by [@vidmantas](https://github.com/vidmantas)
4
+
1
5
  ## 0.4.2 - August 19, 2015
2
6
 
3
7
  - Improve `failure_message_negated` - patch by [@swastik](https://github.com/swastik)
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rspec-activejob (0.4.2)
4
+ rspec-activejob (0.5.0)
5
5
  activejob (>= 4.2)
6
6
  rspec-mocks
7
7
 
@@ -17,6 +17,9 @@ GEM
17
17
  minitest (~> 5.1)
18
18
  thread_safe (~> 0.3, >= 0.3.4)
19
19
  tzinfo (~> 1.1)
20
+ ast (2.1.0)
21
+ astrolabe (1.3.1)
22
+ parser (~> 2.2)
20
23
  coderay (1.1.0)
21
24
  diff-lcs (1.2.5)
22
25
  globalid (0.3.3)
@@ -25,10 +28,14 @@ GEM
25
28
  json (1.8.2)
26
29
  method_source (0.8.2)
27
30
  minitest (5.5.1)
31
+ parser (2.2.2.6)
32
+ ast (>= 1.1, < 3.0)
33
+ powerpack (0.1.1)
28
34
  pry (0.10.1)
29
35
  coderay (~> 1.1.0)
30
36
  method_source (~> 0.8.1)
31
37
  slop (~> 3.4)
38
+ rainbow (2.0.0)
32
39
  rspec (3.2.0)
33
40
  rspec-core (~> 3.2.0)
34
41
  rspec-expectations (~> 3.2.0)
@@ -45,6 +52,13 @@ GEM
45
52
  diff-lcs (>= 1.2.0, < 2.0)
46
53
  rspec-support (~> 3.2.0)
47
54
  rspec-support (3.2.2)
55
+ rubocop (0.34.1)
56
+ astrolabe (~> 1.3)
57
+ parser (>= 2.2.2.5, < 3.0)
58
+ powerpack (~> 0.1)
59
+ rainbow (>= 1.99.1, < 3.0)
60
+ ruby-progressbar (~> 1.4)
61
+ ruby-progressbar (1.7.5)
48
62
  slop (3.6.0)
49
63
  thread_safe (0.3.5)
50
64
  tzinfo (1.2.2)
@@ -59,6 +73,7 @@ DEPENDENCIES
59
73
  rspec
60
74
  rspec-activejob!
61
75
  rspec-its
76
+ rubocop
62
77
 
63
78
  BUNDLED WITH
64
79
  1.10.6
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
- # Instalation
1
+ ![TravisCI status](https://travis-ci.org/gocardless/rspec-activejob.svg?branch=master)
2
+ # Installation
2
3
 
3
4
  ```gem install rspec-activejob ```
4
5
 
@@ -39,7 +40,7 @@ RSpec.describe MyController do
39
40
  subject(:make_request) { described_class.make_request(params) }
40
41
 
41
42
  specify { expect { make_request }.to enqueue_a(RequestMaker).with(global_id(user)) }
42
-
43
+
43
44
  # or
44
45
  make_request
45
46
  expect(RequestMaker).to have_been_enqueued.with(global_id(user))
@@ -48,7 +49,7 @@ end
48
49
 
49
50
  rspec-activejob expects the current queue adapter to expose an array of `enqueued_jobs`, like the included
50
51
  test adapter. The test adapter included in ActiveJob 4.2.0 does not fully serialize its arguments, so you
51
- will not need to use the GlobalID matcher unless you're using ActiveJob 4.2.1. See rails/rails#18266 for
52
+ will not need to use the GlobalID matcher unless you're using ActiveJob 4.2.1. See rails/rails#18266 for
52
53
  the improved test adapter.
53
54
 
54
55
  This gem defines four matchers:
@@ -56,6 +57,7 @@ This gem defines four matchers:
56
57
  * `enqueue_a`: for a block or proc, expects that to enqueue an job to the ActiveJob test adapter. Optionally
57
58
  takes the job class as its argument, and can be modified with a `.with(*args)` call to expect specific arguments.
58
59
  This will use the same argument list matcher as rspec-mocks' `receive(:message).with(*args)` matcher.
60
+ If your job uses `set(wait_until: time)`, you can use `.to_run_at(time)` chain after `enqueue_a` call as well.
59
61
 
60
62
  * `have_been_enqueued`: expects to have enqueued an job in the ActiveJob test adapter. Can be modified with a `.with(*args)` call to expect specific arguments. This will use the same argument list matcher as rspec-mocks' `receive(:message).with(*args)` matcher.
61
63
 
@@ -8,9 +8,11 @@ module RSpec
8
8
  Matchers::EnqueueA.new(job_class)
9
9
  end
10
10
 
11
+ # rubocop:disable Style/PredicateName
11
12
  def have_been_enqueued
12
13
  Matchers::EnqueueA.new
13
14
  end
15
+ # rubocop:enable Style/PredicateName
14
16
 
15
17
  def global_id(expected)
16
18
  Matchers::GlobalID.new(expected)
@@ -14,11 +14,11 @@ module RSpec
14
14
  if actual.is_a?(Proc)
15
15
  @before_jobs = enqueued_jobs.dup
16
16
  actual.call
17
- enqueued_something? && enqueued_correct_class? && with_correct_args?
17
+ all_checks_pass?
18
18
  else
19
19
  @job_class = actual
20
20
  @before_jobs = []
21
- enqueued_something? && enqueued_correct_class? && with_correct_args?
21
+ all_checks_pass?
22
22
  end
23
23
  end
24
24
 
@@ -27,19 +27,16 @@ module RSpec
27
27
  self
28
28
  end
29
29
 
30
- def failure_message
31
- unless enqueued_something?
32
- return "expected to enqueue a #{job_class || 'job'}, enqueued nothing"
33
- end
34
-
35
- unless enqueued_correct_class?
36
- return "expected to enqueue a #{job_class}, " \
37
- "enqueued a #{enqueued_jobs.last[:job]}"
38
- end
30
+ def to_run_at(time)
31
+ @run_time = time.to_f
32
+ self
33
+ end
39
34
 
40
- "expected to enqueue a #{job_class} with " \
41
- "#{argument_list_matcher.expected_args}, but enqueued with " \
42
- "#{new_jobs_with_correct_class.first[:args]}"
35
+ def failure_message
36
+ enqueued_nothing_message ||
37
+ enqueued_wrong_class_message ||
38
+ enqueued_at_wrong_time_message ||
39
+ wrong_arguments_message
43
40
  end
44
41
 
45
42
  def failure_message_when_negated
@@ -69,7 +66,15 @@ module RSpec
69
66
 
70
67
  private
71
68
 
72
- attr_reader :before_count, :after_count, :job_class, :argument_list_matcher
69
+ attr_reader :before_count, :after_count, :job_class, :argument_list_matcher,
70
+ :run_time
71
+
72
+ def all_checks_pass?
73
+ enqueued_something? &&
74
+ enqueued_correct_class? &&
75
+ with_correct_args? &&
76
+ at_correct_time?
77
+ end
73
78
 
74
79
  def enqueued_something?
75
80
  new_jobs.any?
@@ -85,6 +90,29 @@ module RSpec
85
90
  new_jobs_with_correct_class_and_args.any?
86
91
  end
87
92
 
93
+ def enqueued_nothing_message
94
+ return if enqueued_something?
95
+ "expected to enqueue a #{job_class || 'job'}, enqueued nothing"
96
+ end
97
+
98
+ def enqueued_wrong_class_message
99
+ return if enqueued_correct_class?
100
+ "expected to enqueue a #{job_class}, enqueued a " \
101
+ "#{enqueued_jobs.last[:job]}"
102
+ end
103
+
104
+ def enqueued_at_wrong_time_message
105
+ return if at_correct_time?
106
+ "expected to run job at #{Time.at(run_time).utc}, but enqueued to " \
107
+ "run at #{format_enqueued_times}"
108
+ end
109
+
110
+ def wrong_arguments_message
111
+ "expected to enqueue a #{job_class} with " \
112
+ "#{argument_list_matcher.expected_args}, but enqueued with " \
113
+ "#{new_jobs_with_correct_class.first[:args]}"
114
+ end
115
+
88
116
  def new_jobs
89
117
  enqueued_jobs - @before_jobs
90
118
  end
@@ -101,6 +129,16 @@ module RSpec
101
129
  def enqueued_jobs
102
130
  ::ActiveJob::Base.queue_adapter.enqueued_jobs
103
131
  end
132
+
133
+ def at_correct_time?
134
+ return true unless run_time
135
+
136
+ !new_jobs_with_correct_class.find { |job| job[:at] == run_time }.nil?
137
+ end
138
+
139
+ def format_enqueued_times
140
+ new_jobs_with_correct_class.map { |job| Time.at(job[:at]).utc.to_s }.join(', ')
141
+ end
104
142
  end
105
143
  end
106
144
  end
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module ActiveJob
3
- VERSION = '0.4.2'.freeze
3
+ VERSION = '0.5.0'.freeze
4
4
  end
5
5
  end
@@ -25,4 +25,5 @@ Gem::Specification.new do |s|
25
25
  s.add_development_dependency('rspec')
26
26
  s.add_development_dependency('rspec-its')
27
27
  s.add_development_dependency('activesupport')
28
+ s.add_development_dependency('rubocop')
28
29
  end
@@ -148,4 +148,31 @@ RSpec.describe RSpec::ActiveJob::Matchers::EnqueueA do
148
148
  end
149
149
  end
150
150
  end
151
+
152
+ context "with run time expectations" do
153
+ let(:instance) { described_class.new }
154
+ let(:run_time) { Time.parse('2015-09-10 00:00:00 UTC').to_f }
155
+ subject(:matches?) { instance.to_run_at(run_time).matches?(AJob) }
156
+
157
+ let(:enqueued_jobs) do
158
+ [{ job: AJob, args: [], at: time }]
159
+ end
160
+
161
+ context "correct time" do
162
+ let(:time) { run_time }
163
+ it { is_expected.to be(true) }
164
+ end
165
+
166
+ context "wrong time" do
167
+ let(:time) { run_time + 1 }
168
+ it { is_expected.to be(false) }
169
+
170
+ specify do
171
+ matches?
172
+ expect(instance.failure_message).
173
+ to eq("expected to run job at 2015-09-10 00:00:00 UTC, " \
174
+ "but enqueued to run at 2015-09-10 00:00:01 UTC")
175
+ end
176
+ end
177
+ end
151
178
  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.2
4
+ version: 0.5.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-08-19 00:00:00.000000000 Z
11
+ date: 2015-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activejob
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  description: |2
84
98
  RSpec matchers for ActiveJob:
85
99
  * expect { method }.to enqueue_a(MyJob).with(global_id(some_model),
@@ -92,7 +106,7 @@ extra_rdoc_files: []
92
106
  files:
93
107
  - ".gitignore"
94
108
  - ".rubocop.yml"
95
- - ".rubocop_todo.yml"
109
+ - ".travis.yml"
96
110
  - CHANGELOG.md
97
111
  - Gemfile
98
112
  - Gemfile.lock
@@ -1,23 +0,0 @@
1
- # This configuration was generated by `rubocop --auto-gen-config`
2
- # on 2015-05-05 20:58:29 +0100 using RuboCop version 0.27.1.
3
- # The point is for the user to remove these configuration records
4
- # one by one as the offenses are removed from the code base.
5
- # Note that changes in the inspected code, or installation of new
6
- # versions of RuboCop, may require this file to be generated again.
7
-
8
- # Offense count: 1
9
- Metrics/AbcSize:
10
- Max: 16
11
-
12
- # Offense count: 1
13
- Metrics/CyclomaticComplexity:
14
- Max: 8
15
-
16
- # Offense count: 1
17
- Metrics/PerceivedComplexity:
18
- Max: 9
19
-
20
- # Offense count: 1
21
- # Configuration parameters: NamePrefix, NamePrefixBlacklist.
22
- Style/PredicateName:
23
- Enabled: false