jets-testing 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d1620d720260799aea4037feace5362ddd337492bc3be68cf44700ccd7e9a5fe
4
+ data.tar.gz: c20c2b0d5a81f13fe92c0bf12551335fb2e1238c688a028dd6c6782e213c4bd3
5
+ SHA512:
6
+ metadata.gz: 22c7dd5c728ec1ef799ceeebc3fd80728ca8ef92148ff2ddc101c5e2d2d9b4498857550b4a28cfa1113c5a66ebc12f54da621aad6781ba21d3334f8e1e0ee3d9
7
+ data.tar.gz: d4274e6a9da31b07bf3437c79b7f257f562948430e0cdd42468d126831c323ac9b2316d3e98b264b9e78bf2a7cc2d0e3f7e3fd351193ba7ecbb774302bea900b
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+
5
+ begin
6
+ require "bundler/setup"
7
+ rescue LoadError
8
+ puts "You must `gem install bundler` and `bundle install` to run rake tasks"
9
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "jets/testing"
@@ -0,0 +1 @@
1
+ # frozen_string_literal: true
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionDispatch
4
+ # Make response less verbose (for RSpec failure messages).
5
+ #
6
+ # Before:
7
+ # expected `#<ActionDispatch::TestResponse:0x000055c409b14a40
8
+ # @mon_owner=nil, @mon_count=0,
9
+ # @mon_mutex=#<Thread::...ext/html", @hash=459027022919608650>,
10
+ # @charset="utf-8", @cache_control={:no_cache=>true},
11
+ # @etag=nil>.success?` to return true, got false
12
+ #
13
+ # After:
14
+ # expected `TestResponse<status: 302, content-type: text/html,
15
+ # body: "<html><body>You are being redirected</a>..."
16
+ # >.success?` to return true, got false
17
+ class TestResponse
18
+ def inspect
19
+ "TestResponse<status: #{status}, " \
20
+ "content-type: #{content_type}, " \
21
+ "body: \"#{body.truncate(200)}\">"
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Hijack Bundler.require from Combustion.initialize! to load engine-specific group
4
+ Combustion.singleton_class.prepend(Module.new do
5
+ def initialize!(*args, bundler_groups: nil, **kwargs)
6
+ if bundler_groups
7
+ original_require = Bundler.method(:require)
8
+ Bundler.define_singleton_method(:require) { |*| original_require.call(*bundler_groups) }
9
+ end
10
+
11
+ super
12
+ ensure
13
+ Bundler.define_singleton_method(:require, original_require) if bundler_groups
14
+ end
15
+ end)
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Disable Isolator in n_plus_one_control examples
4
+ #
5
+ # Rails 5 triggers `after_commit` callbacks depending on the properties of the outer transaction:
6
+ # if it has `joinable: false` then callbacks are triggered.
7
+ # `n_plus_one_control` also uses a non-joinable transaction, but it's not counted as _safe_ by Isolator,
8
+ # 'cause it opens after the test example transaction (`transactional_tests` feature).
9
+ #
10
+ # Links:
11
+ # - https://github.com/palkan/n_plus_one_control/blob/d13567e60c18bb2e85e606abee4c096383623992/lib/n_plus_one_control/executor.rb#L59
12
+ NPlusOneControl::Executor.singleton_class.prepend(Module.new do
13
+ def with_transaction(*)
14
+ Isolator.disable { super }
15
+ end
16
+ end)
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jets::Testing
4
+ module FileFixtureHelper
5
+ def fixture_file_path(*paths)
6
+ File.join(RSpec.configuration.file_fixture_path, *paths)
7
+ end
8
+ end
9
+ end
10
+
11
+ RSpec.configure do |config|
12
+ config.include Jets::Testing::FileFixtureHelper
13
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jets::Testing
4
+ module JSONResponse
5
+ def json_response
6
+ @json_response ||= begin
7
+ request
8
+ JSON.parse(response.body)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jets::Testing
4
+ module MailboxForHelper
5
+ class Mailbox
6
+ attr_reader :email
7
+
8
+ delegate :count, :size, :last, to: :deliveries
9
+
10
+ def initialize(email)
11
+ @email = email
12
+ end
13
+
14
+ def deliveries
15
+ ActionMailer::Base.deliveries.select do |mail|
16
+ mail.destinations.include?(email)
17
+ end
18
+ end
19
+ end
20
+
21
+ def mails_for(user_or_email)
22
+ if ActionMailer::Base.delivery_method != :test
23
+ raise "You can only use `mailbox` helper when" \
24
+ "ActionMailer::Base.delivery_method is `:test`"
25
+ end
26
+
27
+ email = user_or_email.respond_to?(:email) ? user_or_email.email : user_or_email
28
+
29
+ Mailbox.new(email)
30
+ end
31
+ end
32
+ end
33
+
34
+ RSpec.configure do |config|
35
+ config.include Jets::Testing::MailboxForHelper
36
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "jets-factory"
4
+
5
+ require "rspec/rails"
6
+
7
+ require "isolator"
8
+ require "n_plus_one_control/rspec"
9
+ require "shoulda-matchers"
10
+ require "timecop"
11
+ require "with_model"
12
+
13
+ require "jets/testing/ext/action_dispatch_test_response"
14
+ require "jets/testing/ext/n_plus_one_control_isolator"
15
+
16
+ require "test_prof/recipes/rspec/before_all"
17
+ require "test_prof/recipes/rspec/let_it_be"
18
+ require "test_prof/recipes/logging"
19
+ require "test_prof/recipes/rspec/any_fixture"
20
+ require "test_prof/ext/active_record_refind"
21
+ require "test_prof/any_fixture/dsl"
22
+ require "test_prof/recipes/rspec/factory_default"
23
+ require "test_prof/recipes/rspec/sample"
24
+
25
+ Dir[File.join(__dir__, "helpers/**/*.rb")].each { |file| require file }
26
+ Dir[File.join(__dir__, "shared_contexts/**/*.rb")].each { |file| require file }
27
+
28
+ Shoulda::Matchers.configure do |config|
29
+ config.integrate do |with|
30
+ with.test_framework :rspec
31
+ with.library :rails
32
+ end
33
+ end
34
+
35
+ NPlusOneControl.verbose = true
36
+
37
+ root = defined?(ENGINE_ROOT) ? Pathname.new(ENGINE_ROOT) : Rails.root
38
+
39
+ Dir[root.join("spec/support/**/*.rb")].each { |file| require file }
40
+
41
+ RSpec.configure do |config|
42
+ config.fixture_path = root.join("spec/fixtures")
43
+
44
+ config.include ActionDispatch::TestProcess
45
+ config.include FactoryBot::Syntax::Methods
46
+ config.include ActiveSupport::Testing::TimeHelpers
47
+ config.extend WithModel
48
+
49
+ config.use_transactional_fixtures = true
50
+
51
+ config.infer_spec_type_from_file_location!
52
+
53
+ unless ENV["FULLTRACE"]
54
+ config.filter_rails_from_backtrace!
55
+ config.filter_gems_from_backtrace "railties", "rack", "rack-test"
56
+ end
57
+
58
+ config.after(:each) do
59
+ Timecop.return
60
+ travel_back
61
+
62
+ if defined?(ActiveJob) && ActiveJob::QueueAdapters::TestAdapter === ActiveJob::Base.queue_adapter
63
+ ActiveJob::Base.queue_adapter.enqueued_jobs.clear
64
+ ActiveJob::Base.queue_adapter.performed_jobs.clear
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rspec"
4
+ require "rspec/instafail"
5
+ require "rspec_junit_formatter"
6
+ require "rspec/support/spec/shell_out"
7
+
8
+ RSpec.configure do |config|
9
+ include RSpec::Support::ShellOut
10
+
11
+ config.expect_with :rspec do |expectations|
12
+ # This option will default to `true` in RSpec 4. It makes the `description`
13
+ # and `failure_message` of custom matchers include text for helper methods
14
+ # defined using `chain`, e.g.:
15
+ # be_bigger_than(2).and_smaller_than(4).description
16
+ # # => "be bigger than 2 and smaller than 4"
17
+ # ...rather than:
18
+ # # => "be bigger than 2"
19
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
20
+ end
21
+
22
+ config.mock_with :rspec do |mocks|
23
+ # Prevents you from mocking or stubbing a method that does not exist on
24
+ # a real object. This is generally recommended, and will default to
25
+ # `true` in RSpec 4.
26
+ mocks.verify_partial_doubles = true
27
+ end
28
+
29
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
30
+ # have no way to turn it off -- the option exists only for backwards
31
+ # compatibility in RSpec 3). It causes shared context metadata to be
32
+ # inherited by the metadata hash of host groups and examples, rather than
33
+ # triggering implicit auto-inclusion in groups with matching metadata.
34
+ config.shared_context_metadata_behavior = :apply_to_host_groups
35
+
36
+ config.define_derived_metadata(file_path: %r{/spec/}) do |metadata|
37
+ next if metadata.key?(:type)
38
+ match = metadata[:location].match(%r{/spec/([^/]+)/})
39
+ next unless match
40
+ metadata[:type] = match[1].then do |path|
41
+ next path unless path.respond_to?(:singularize)
42
+ path.singularize
43
+ end.to_sym
44
+ end
45
+
46
+ config.filter_run_when_matching :focus
47
+ config.example_status_persistence_file_path = "tmp/rspec_examples.txt"
48
+ config.run_all_when_everything_filtered = true
49
+
50
+ if config.files_to_run.one?
51
+ # Use the documentation formatter for detailed output,
52
+ # unless a formatter has already been configured
53
+ # (e.g. via a command-line flag).
54
+ config.default_formatter = "doc"
55
+ end
56
+
57
+ unless ENV["FULLTRACE"]
58
+ config.filter_gems_from_backtrace "factory_bot"
59
+ config.filter_gems_from_backtrace "graphql"
60
+ config.filter_gems_from_backtrace "test-prof"
61
+ end
62
+
63
+ # Always include the spec itself to the backtrace.
64
+ # That also helps to avoid a full stack printing when
65
+ # everything have been filtered out.
66
+ config.backtrace_inclusion_patterns << %r{/spec/}
67
+
68
+ config.order = :random
69
+ Kernel.srand config.seed
70
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ shared_context "active_job:perform" do
4
+ around do |ex|
5
+ current = ActiveJob::Base.queue_adapter.perform_enqueued_jobs
6
+ ActiveJob::Base.queue_adapter.perform_enqueued_jobs = true
7
+ ex.run
8
+ ActiveJob::Base.queue_adapter.perform_enqueued_jobs = current
9
+ end
10
+ end
11
+
12
+ RSpec.configure do |config|
13
+ config.include_context "active_job:perform", active_job: :perform
14
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ shared_context "csrf:on" do
4
+ around do |ex|
5
+ current = ActionController::Base.allow_forgery_protection
6
+ ActionController::Base.allow_forgery_protection = true
7
+ ex.run
8
+ ActionController::Base.allow_forgery_protection = current
9
+ end
10
+ end
11
+
12
+ RSpec.configure do |config|
13
+ config.include_context "csrf:on", csrf: :on
14
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ shared_context "shared:request" do
4
+ subject { request; response }
5
+ end
6
+
7
+ RSpec.configure do |config|
8
+ config.include_context "shared:request", type: :request
9
+ config.include Jets::Testing::JSONResponse, type: :request
10
+ end
metadata ADDED
@@ -0,0 +1,294 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jets-testing
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Lauri Jutila
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-11-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '6.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '6.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec-rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 4.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 4.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: combustion
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: isolator
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.6.2
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.6.2
69
+ - !ruby/object:Gem::Dependency
70
+ name: n_plus_one_control
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.3.1
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.3.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: shoulda-matchers
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '4.4'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '4.4'
97
+ - !ruby/object:Gem::Dependency
98
+ name: test-prof
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.10.1
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.10.1
111
+ - !ruby/object:Gem::Dependency
112
+ name: timecop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.9'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.9'
125
+ - !ruby/object:Gem::Dependency
126
+ name: with_model
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '2.1'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '2.1'
139
+ - !ruby/object:Gem::Dependency
140
+ name: fuubar
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '2.5'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '2.5'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rspec-instafail
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '1.0'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '1.0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: rspec_junit_formatter
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '0.4'
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: '0.4'
181
+ - !ruby/object:Gem::Dependency
182
+ name: jets-factory
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: '0.1'
188
+ type: :runtime
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: '0.1'
195
+ - !ruby/object:Gem::Dependency
196
+ name: bundler
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - "~>"
200
+ - !ruby/object:Gem::Version
201
+ version: '2'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - "~>"
207
+ - !ruby/object:Gem::Version
208
+ version: '2'
209
+ - !ruby/object:Gem::Dependency
210
+ name: pry-byebug
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - "~>"
214
+ - !ruby/object:Gem::Version
215
+ version: '3.6'
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - "~>"
221
+ - !ruby/object:Gem::Version
222
+ version: '3.6'
223
+ - !ruby/object:Gem::Dependency
224
+ name: rake
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - "~>"
228
+ - !ruby/object:Gem::Version
229
+ version: '13.0'
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - "~>"
235
+ - !ruby/object:Gem::Version
236
+ version: '13.0'
237
+ - !ruby/object:Gem::Dependency
238
+ name: jets-rubocop
239
+ requirement: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - "~>"
242
+ - !ruby/object:Gem::Version
243
+ version: '0.1'
244
+ type: :development
245
+ prerelease: false
246
+ version_requirements: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - "~>"
249
+ - !ruby/object:Gem::Version
250
+ version: '0.1'
251
+ description: Common configuration for RSpec and a dummy application
252
+ email: ruby@laurijutila.com
253
+ executables: []
254
+ extensions: []
255
+ extra_rdoc_files: []
256
+ files:
257
+ - Rakefile
258
+ - lib/jets-testing.rb
259
+ - lib/jets/testing.rb
260
+ - lib/jets/testing/ext/action_dispatch_test_response.rb
261
+ - lib/jets/testing/ext/combustion_bundler_patch.rb
262
+ - lib/jets/testing/ext/n_plus_one_control_isolator.rb
263
+ - lib/jets/testing/helpers/file_fixture_helper.rb
264
+ - lib/jets/testing/helpers/json_response.rb
265
+ - lib/jets/testing/helpers/mailbox_for_helper.rb
266
+ - lib/jets/testing/rails.rb
267
+ - lib/jets/testing/rspec.rb
268
+ - lib/jets/testing/shared_contexts/active_job.rb
269
+ - lib/jets/testing/shared_contexts/csrf.rb
270
+ - lib/jets/testing/shared_contexts/shared_request.rb
271
+ homepage: https://github.com/getjets/jets-testing
272
+ licenses:
273
+ - MIT
274
+ metadata: {}
275
+ post_install_message:
276
+ rdoc_options: []
277
+ require_paths:
278
+ - lib
279
+ required_ruby_version: !ruby/object:Gem::Requirement
280
+ requirements:
281
+ - - ">="
282
+ - !ruby/object:Gem::Version
283
+ version: '0'
284
+ required_rubygems_version: !ruby/object:Gem::Requirement
285
+ requirements:
286
+ - - ">="
287
+ - !ruby/object:Gem::Version
288
+ version: '0'
289
+ requirements: []
290
+ rubygems_version: 3.1.2
291
+ signing_key:
292
+ specification_version: 4
293
+ summary: Common configuration for RSpec and a dummy application
294
+ test_files: []