queue_classic_matchers 0.0.1 → 1.1.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
- SHA1:
3
- metadata.gz: 8cfabef2f107163c77342e176369028419df0b9e
4
- data.tar.gz: 7c3e40864f608225424faa87aa95c55d5dc0df50
2
+ SHA256:
3
+ metadata.gz: 4c9c20b4638520c3bb0c5b8e9dbc64202d9fb9d59f0e29dc194a28d5d3b7020a
4
+ data.tar.gz: 82a3d2dc873586ee2d857a70494fd7055ff49bf771f9ab7608608fb6e760c32f
5
5
  SHA512:
6
- metadata.gz: 68fcb9b92713b041b25859fc6ed13024023e5a55b9a0504d2098359faa0e66af21147c28e29aa005018dc8cbdc3951ce2dca4a01fc3068669e5f5e6ba7574173
7
- data.tar.gz: 7d3997f9b70c53a8d1c98ed5a1624b41960d1701ac74972e91d802a84b083ad4209ddfefee0757d636943601cc0ab7aa936e3358f62fdd7e1643075cc16f5408
6
+ metadata.gz: 416468f930e73965959db66ddf2cdbe06f66cca892efa20da415025650006d1d18f61082a2a5c08bea3efb0731c005cfb72b96dafa0dfa86f4e17143b30efe33
7
+ data.tar.gz: 5e935730577ce891f07b48ee5d90b605824a95d412bc1d0a3ce0f118e3b6549daace6cf51ad08dc9975df4baa6bafc8200b86049c93a5e474fee9157c480cf17
@@ -0,0 +1,48 @@
1
+ version: 2
2
+
3
+ jobs:
4
+ test:
5
+ docker:
6
+ - image: circleci/ruby:2.5.3-node
7
+ - image: circleci/postgres:9.6.6-alpine
8
+ steps:
9
+ - checkout
10
+ - run:
11
+ name: run tests
12
+ command: |
13
+ bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3
14
+ bundle exec rspec
15
+
16
+ push_to_rubygems:
17
+ docker:
18
+ - image: circleci/ruby:2.5.3
19
+ steps:
20
+ - checkout
21
+ - run:
22
+ name: Create .gem/credentials file
23
+ command: |
24
+ mkdir ~/.gem
25
+ echo "---
26
+ :rubygems_api_key: $RUBYGEMS_API_KEY
27
+ " > ~/.gem/credentials
28
+ chmod 600 ~/.gem/credentials
29
+ - run:
30
+ name: Release to rubygems
31
+ command: |
32
+ gem build queue_classic_matchers
33
+ gem push queue_classic_matchers-*.gem
34
+
35
+ workflows:
36
+ version: 2
37
+ gem_release:
38
+ jobs:
39
+ - test
40
+
41
+ - push_to_rubygems:
42
+ filters:
43
+ branches:
44
+ ignore:
45
+ - /.*/
46
+ tags:
47
+ only:
48
+ - /^v.*/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile CHANGED
@@ -2,3 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in queue_classic_matchers.gemspec
4
4
  gemspec
5
+
6
+ gem 'rspec'
7
+ # TODO: release qc plus
8
+ gem 'queue_classic_plus', github: 'rainforestapp/queue_classic_plus', tag: 'v4.0.0-alpha2'
data/README.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  Test helpers and RSpec matchers to [QueueClassicPlus](https://github.com/rainforestapp/queue_classic_plus).
4
4
 
5
+ ## Compatibility
6
+
7
+ This version of the matchers are compatible with queue_classic 3.1+ which includes built-in scheduling. See other branches for other compatible versions.
8
+
5
9
  ## Installation
6
10
 
7
11
  Add this line to your application's Gemfile:
@@ -26,6 +30,8 @@ TODO: Write usage instructions here
26
30
  expect(MyQueueClassicPlusJob).to have_queued(*my_args)
27
31
  ```
28
32
 
33
+ Other matchers are `have_queue_size_of`, `change_queue_size_of` and `have_scheduled`.
34
+
29
35
 
30
36
  ### Test Helper
31
37
 
@@ -43,3 +49,9 @@ run_queue q_name, [MyQueueClassicPlusJob]
43
49
  3. Commit your changes (`git commit -am 'Add some feature'`)
44
50
  4. Push to the branch (`git push origin my-new-feature`)
45
51
  5. Create a new Pull Request
52
+
53
+ ## Releasing
54
+
55
+ 1. Open a PR and get it merged to master, making sure you've updated VERSION in `lib/queue_classic_matchers/version.rb`
56
+ 2. `git checkout master; git pull`
57
+ 3. `rake release:source_control_push`
data/Rakefile CHANGED
@@ -1,2 +1,2 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
2
 
@@ -1,21 +1,48 @@
1
1
  require 'rspec/matchers'
2
- require "queue_classic_matchers/version"
3
- require "queue_classic_matchers/test_worker"
4
- require "queue_classic_matchers/test_helper"
2
+ require 'rspec/core'
3
+ require 'queue_classic_matchers/version'
4
+ require 'queue_classic_matchers/test_worker'
5
+ require 'queue_classic_matchers/test_helper'
5
6
 
6
7
  module QueueClassicMatchers
7
8
  # Your code goes here...
8
9
  module QueueClassicMatchers::QueueClassicRspec
9
- def self.find_by_args(queue_name, method, args, table = "queue_classic_jobs")
10
- q = "SELECT * FROM #{table} WHERE q_name = $1 AND method = $2 AND args::text = $3"
10
+ def self.find_by_args(queue_name, method, args)
11
+ q = 'SELECT * FROM queue_classic_jobs WHERE q_name = $1 AND method = $2 AND args::text = $3'
11
12
  result = QC.default_conn_adapter.execute q, queue_name, method, JSON.dump(args)
12
13
  result = [result] unless Array === result
13
14
  result.compact
14
15
  end
15
16
 
16
17
  def self.reset!
17
- QC.default_conn_adapter.execute "DELETE FROM queue_classic_jobs"
18
- QC.default_conn_adapter.execute "DELETE FROM queue_classic_later_jobs"
18
+ QC.default_conn_adapter.execute 'DELETE FROM queue_classic_jobs'
19
+ end
20
+ end
21
+
22
+ if defined?(QueueClassicPlus)
23
+ module QueueClassicPlus
24
+ module Job
25
+ def self.included(receiver)
26
+ receiver.class_eval do
27
+ shared_examples_for 'a queueable class' do
28
+ subject { described_class }
29
+ its(:queue) { should be_a(::QC::Queue) }
30
+ it { should respond_to(:do) }
31
+ it { should respond_to(:perform) }
32
+
33
+ it 'should be a valid queue name' do
34
+ expect(subject.queue.name).to be_present
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ if RSpec.respond_to?(:configure)
43
+ RSpec.configure do |c|
44
+ c.include QueueClassicMatchers::QueueClassicPlus::Job, type: :job
45
+ end
19
46
  end
20
47
  end
21
48
  end
@@ -37,7 +64,7 @@ RSpec::Matchers.define :have_queued do |*expected|
37
64
  end
38
65
 
39
66
  description do
40
- "should enqueue in queue classic"
67
+ 'should enqueue in queue classic'
41
68
  end
42
69
  end
43
70
 
@@ -87,14 +114,13 @@ RSpec::Matchers.define :change_queue_size_of do |expected|
87
114
  end
88
115
 
89
116
  description do
90
- "should change the queue size"
117
+ 'should change the queue size'
91
118
  end
92
119
  end
93
120
 
94
121
 
95
122
  RSpec::Matchers.define :have_scheduled do |*expected_args|
96
123
  chain :at do |timestamp|
97
- @interval = nil
98
124
  @time = timestamp
99
125
  @time_info = "at #{@time}"
100
126
  end
@@ -102,13 +128,13 @@ RSpec::Matchers.define :have_scheduled do |*expected_args|
102
128
  match do |actual|
103
129
  method = "#{actual.to_s}._perform"
104
130
  queue_name = actual.queue.name
105
- results = QueueClassicMatchers::QueueClassicRspec.find_by_args(queue_name,
106
- method,
107
- expected_args,
108
- "queue_classic_later_jobs")
131
+ results = QueueClassicMatchers::QueueClassicRspec.find_by_args(queue_name, method, expected_args)
132
+
109
133
  results.any? do |entry|
110
- time_matches = if @time
111
- Time.parse(entry['not_before']).to_i == @time.to_i
134
+ if @time
135
+ scheduled_at = entry['scheduled_at']
136
+ scheduled_at = Time.parse(scheduled_at) unless scheduled_at.is_a?(Time) # ActiveRecord < 6
137
+ (scheduled_at.to_i - @time.to_i).abs <= 2
112
138
  else
113
139
  true
114
140
  end
@@ -124,6 +150,6 @@ RSpec::Matchers.define :have_scheduled do |*expected_args|
124
150
  end
125
151
 
126
152
  description do
127
- "have scheduled arguments"
153
+ 'have scheduled arguments'
128
154
  end
129
155
  end
@@ -1,3 +1,3 @@
1
1
  module QueueClassicMatchers
2
- VERSION = "0.0.1"
2
+ VERSION = '1.1.0'
3
3
  end
@@ -4,20 +4,22 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'queue_classic_matchers/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "queue_classic_matchers"
7
+ spec.name = 'queue_classic_matchers'
8
8
  spec.version = QueueClassicMatchers::VERSION
9
- spec.authors = ["Simon Mathieu"]
10
- spec.email = ["simon.math@gmail.com"]
9
+ spec.authors = ['Simon Mathieu', 'Jean-Philippe Boily', 'Emanuel Evans', 'Jonathan Barber']
11
10
  spec.summary = %q{RSpec Matchers and helpers for QueueClassicPlus}
12
- spec.description = %q{RSpec Matchers and helpers for QueueClassicPlus}
13
- spec.homepage = ""
14
- spec.license = "MIT"
11
+ spec.homepage = 'https://github.com/rainforestapp/queue_classic_matchers'
12
+ spec.license = 'MIT'
15
13
 
16
14
  spec.files = `git ls-files -z`.split("\x0")
17
15
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
16
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
17
+ spec.require_paths = ['lib']
20
18
 
21
- spec.add_development_dependency "bundler", "~> 1.6"
22
- spec.add_development_dependency "rake"
19
+ spec.add_dependency 'queue_classic', '>= 3.1.0'
20
+ spec.add_development_dependency 'activerecord'
21
+ spec.add_development_dependency 'bundler'
22
+ spec.add_development_dependency 'pg'
23
+ spec.add_development_dependency 'rake'
24
+ spec.add_development_dependency 'timecop'
23
25
  end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe QueueClassicMatchers do
4
+ class TestJob < QueueClassicPlus::Base
5
+ @queue = :low
6
+ def self.perform
7
+ end
8
+ end
9
+
10
+ describe 'have_queued' do
11
+ it 'works with no arguments' do
12
+ expect(TestJob).to_not have_queued
13
+ TestJob.do
14
+ expect(TestJob).to have_queued
15
+ end
16
+
17
+ it 'works wiht argument' do
18
+ expect(TestJob).to_not have_queued(1)
19
+ TestJob.do 1
20
+ expect(TestJob).to have_queued(1)
21
+ expect(TestJob).to_not have_queued(2)
22
+ end
23
+ end
24
+
25
+ describe 'have_queue_size_of' do
26
+ it 'works' do
27
+ expect(TestJob).to have_queue_size_of(0)
28
+ expect(TestJob).to_not have_queue_size_of(1)
29
+
30
+ TestJob.do
31
+
32
+ expect(TestJob).to have_queue_size_of(1)
33
+ expect(TestJob).to_not have_queue_size_of(0)
34
+ end
35
+ end
36
+
37
+ describe 'have_scheduled' do
38
+ it 'works' do
39
+ Timecop.freeze do
40
+ t0 = Time.now
41
+ TestJob.enqueue_perform_in 60 * 60, 1
42
+
43
+ expect(TestJob).to have_scheduled(1).at(t0 + 60 * 60)
44
+ expect(TestJob).not_to have_scheduled(1).at(t0 + 60 * 60 - 3)
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,123 @@
1
+ require 'queue_classic_plus'
2
+ require 'queue_classic_matchers'
3
+ require 'timecop'
4
+ # This file was generated by the `rspec --init` command. Conventionally, all
5
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
6
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
7
+ # this file to always be loaded, without a need to explicitly require it in any
8
+ # files.
9
+ #
10
+ # Given that it is always loaded, you are encouraged to keep this file as
11
+ # light-weight as possible. Requiring heavyweight dependencies from this file
12
+ # will add to the boot time of your test suite on EVERY test run, even for an
13
+ # individual file that may not need all of that loaded. Instead, consider making
14
+ # a separate helper file that requires the additional dependencies and performs
15
+ # the additional setup, and require it from the spec files that actually need
16
+ # it.
17
+ #
18
+ # The `.rspec` file also contains a few flags that are not defaults but that
19
+ # users commonly want.
20
+ #
21
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
22
+ RSpec.configure do |config|
23
+ # rspec-expectations config goes here. You can use an alternate
24
+ # assertion/expectation library such as wrong or the stdlib/minitest
25
+ # assertions if you prefer.
26
+ config.expect_with :rspec do |expectations|
27
+ # This option will default to `true` in RSpec 4. It makes the `description`
28
+ # and `failure_message` of custom matchers include text for helper methods
29
+ # defined using `chain`, e.g.:
30
+ # be_bigger_than(2).and_smaller_than(4).description
31
+ # # => "be bigger than 2 and smaller than 4"
32
+ # ...rather than:
33
+ # # => "be bigger than 2"
34
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
35
+ end
36
+
37
+ # rspec-mocks config goes here. You can use an alternate test double
38
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
39
+ config.mock_with :rspec do |mocks|
40
+ # Prevents you from mocking or stubbing a method that does not exist on
41
+ # a real object. This is generally recommended, and will default to
42
+ # `true` in RSpec 4.
43
+ mocks.verify_partial_doubles = true
44
+ end
45
+
46
+ # The settings below are suggested to provide a good initial experience
47
+ # with RSpec, but feel free to customize to your heart's content.
48
+ =begin
49
+ # These two settings work together to allow you to limit a spec run
50
+ # to individual examples or groups you care about by tagging them with
51
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
52
+ # get run.
53
+ config.filter_run :focus
54
+ config.run_all_when_everything_filtered = true
55
+
56
+ # Limits the available syntax to the non-monkey patched syntax that is
57
+ # recommended. For more details, see:
58
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
59
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
60
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
61
+ config.disable_monkey_patching!
62
+
63
+ # This setting enables warnings. It's recommended, but in some cases may
64
+ # be too noisy due to issues in dependencies.
65
+ config.warnings = true
66
+
67
+ # Many RSpec users commonly either run the entire suite or an individual
68
+ # file, and it's useful to allow more verbose output when running an
69
+ # individual spec file.
70
+ if config.files_to_run.one?
71
+ # Use the documentation formatter for detailed output,
72
+ # unless a formatter has already been configured
73
+ # (e.g. via a command-line flag).
74
+ config.default_formatter = 'doc'
75
+ end
76
+
77
+ # Print the 10 slowest examples and example groups at the
78
+ # end of the spec run, to help surface which specs are running
79
+ # particularly slow.
80
+ config.profile_examples = 10
81
+
82
+ # Run specs in random order to surface order dependencies. If you find an
83
+ # order dependency and want to debug it, you can fix the order by providing
84
+ # the seed, which is printed after each run.
85
+ # --seed 1234
86
+ config.order = :random
87
+
88
+ # Seed global randomization in this process using the `--seed` CLI option.
89
+ # Setting this allows you to use `--seed` to deterministically reproduce
90
+ # test failures related to randomization by passing the same `--seed` value
91
+ # as the one that triggered the failure.
92
+ Kernel.srand config.seed
93
+ =end
94
+
95
+ config.before(:suite) do
96
+ require 'active_record'
97
+ require 'pg'
98
+
99
+ db_url = ENV.fetch('DATABASE_URL', 'postgres://postgres:@localhost')
100
+
101
+ ActiveRecord::Base.establish_connection(db_url)
102
+ begin
103
+ ActiveRecord::Base.connection.create_database('queue_classic_matcher_test')
104
+ rescue ActiveRecord::StatementInvalid => e
105
+ raise unless e.cause.class == PG::DuplicateDatabase
106
+ end
107
+
108
+ ActiveRecord::Base.connection.execute 'drop schema public cascade; create schema public;'
109
+
110
+ QC.default_conn_adapter = QC::ConnAdapter.new(connection: ActiveRecord::Base.connection.raw_connection)
111
+ QC::Setup.create
112
+
113
+ QueueClassicPlus.migrate
114
+ end
115
+
116
+ config.before(:each) do
117
+ tables = ActiveRecord::Base.connection.tables.select do |table|
118
+ table != 'schema_migrations'
119
+ end
120
+ ActiveRecord::Base.connection.execute("TRUNCATE #{tables.join(', ')} CASCADE") unless tables.empty?
121
+
122
+ end
123
+ end
metadata CHANGED
@@ -1,29 +1,74 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: queue_classic_matchers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Mathieu
8
+ - Jean-Philippe Boily
9
+ - Emanuel Evans
10
+ - Jonathan Barber
8
11
  autorequire:
9
12
  bindir: bin
10
13
  cert_chain: []
11
- date: 2014-08-08 00:00:00.000000000 Z
14
+ date: 2020-07-16 00:00:00.000000000 Z
12
15
  dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: queue_classic
18
+ requirement: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 3.1.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 3.1.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: activerecord
32
+ requirement: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ type: :development
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
13
44
  - !ruby/object:Gem::Dependency
14
45
  name: bundler
15
46
  requirement: !ruby/object:Gem::Requirement
16
47
  requirements:
17
- - - "~>"
48
+ - - ">="
18
49
  - !ruby/object:Gem::Version
19
- version: '1.6'
50
+ version: '0'
20
51
  type: :development
21
52
  prerelease: false
22
53
  version_requirements: !ruby/object:Gem::Requirement
23
54
  requirements:
24
- - - "~>"
55
+ - - ">="
25
56
  - !ruby/object:Gem::Version
26
- version: '1.6'
57
+ version: '0'
58
+ - !ruby/object:Gem::Dependency
59
+ name: pg
60
+ requirement: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ type: :development
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
27
72
  - !ruby/object:Gem::Dependency
28
73
  name: rake
29
74
  requirement: !ruby/object:Gem::Requirement
@@ -38,15 +83,29 @@ dependencies:
38
83
  - - ">="
39
84
  - !ruby/object:Gem::Version
40
85
  version: '0'
41
- description: RSpec Matchers and helpers for QueueClassicPlus
42
- email:
43
- - simon.math@gmail.com
86
+ - !ruby/object:Gem::Dependency
87
+ name: timecop
88
+ requirement: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ type: :development
94
+ prerelease: false
95
+ version_requirements: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ description:
101
+ email:
44
102
  executables: []
45
103
  extensions: []
46
104
  extra_rdoc_files: []
47
105
  files:
106
+ - ".circleci/config.yml"
48
107
  - ".gitignore"
49
- - ".rvmrc"
108
+ - ".rspec"
50
109
  - Gemfile
51
110
  - LICENSE.txt
52
111
  - README.md
@@ -56,7 +115,9 @@ files:
56
115
  - lib/queue_classic_matchers/test_worker.rb
57
116
  - lib/queue_classic_matchers/version.rb
58
117
  - queue_classic_matchers.gemspec
59
- homepage: ''
118
+ - spec/queue_classic_matchers_spec.rb
119
+ - spec/spec_helper.rb
120
+ homepage: https://github.com/rainforestapp/queue_classic_matchers
60
121
  licenses:
61
122
  - MIT
62
123
  metadata: {}
@@ -75,9 +136,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
136
  - !ruby/object:Gem::Version
76
137
  version: '0'
77
138
  requirements: []
78
- rubyforge_project:
79
- rubygems_version: 2.2.2
139
+ rubygems_version: 3.0.3
80
140
  signing_key:
81
141
  specification_version: 4
82
142
  summary: RSpec Matchers and helpers for QueueClassicPlus
83
- test_files: []
143
+ test_files:
144
+ - spec/queue_classic_matchers_spec.rb
145
+ - spec/spec_helper.rb
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm use 2.1.2@queue_classic_matchers --create