with_model 2.3.0 → 2.4.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.
@@ -0,0 +1,153 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "open3"
4
+ require "rbconfig"
5
+ require "tmpdir"
6
+
7
+ RSpec.describe "runner integration entrypoints" do
8
+ def run_ruby(source, load_paths: ["lib"])
9
+ Open3.capture3(
10
+ RbConfig.ruby,
11
+ *load_paths.map { |path| "-I#{path}" },
12
+ "-e",
13
+ source
14
+ )
15
+ end
16
+
17
+ def expect_native_runner_to_pass(source, load_paths: ["lib"])
18
+ stdout, stderr, status = run_ruby(source, load_paths:)
19
+
20
+ expect(status).to be_success, <<~MESSAGE
21
+ subprocess failed with status #{status.exitstatus}
22
+ stdout:
23
+ #{stdout}
24
+ stderr:
25
+ #{stderr}
26
+ MESSAGE
27
+ end
28
+
29
+ it "configures RSpec and extends new example groups" do
30
+ expect_native_runner_to_pass(<<~'RUBY')
31
+ require "with_model/rspec"
32
+ abort "runner: #{WithModel.runner.inspect}" unless WithModel.runner == :rspec
33
+
34
+ RSpec.describe "entrypoint" do
35
+ it "installs the DSL" do
36
+ expect(self.class).to respond_to(:with_model)
37
+ end
38
+ end
39
+
40
+ exit RSpec::Core::Runner.run([])
41
+ RUBY
42
+ end
43
+
44
+ it "configures Minitest and extends new test subclasses" do
45
+ expect_native_runner_to_pass(<<~'RUBY')
46
+ require "with_model/minitest"
47
+ abort "runner: #{WithModel.runner.inspect}" unless WithModel.runner == :minitest
48
+
49
+ # Assert that minitest/autorun is not loaded
50
+ autorun_loaded = $LOADED_FEATURES.any? { |f| f.end_with?("/minitest/autorun.rb") }
51
+ abort "autorun should not be loaded; loaded features: #{$LOADED_FEATURES.inspect}" if autorun_loaded
52
+
53
+ class MinitestEntrypointTest < Minitest::Test
54
+ def test_installs_the_dsl
55
+ assert_respond_to self.class, :with_model
56
+ end
57
+ end
58
+
59
+ exit(Minitest.run ? 0 : 1)
60
+ RUBY
61
+ end
62
+
63
+ it "configures Test::Unit and extends new test subclasses" do
64
+ expect_native_runner_to_pass(<<~'RUBY')
65
+ require "with_model/test_unit"
66
+ abort "runner: #{WithModel.runner.inspect}" unless WithModel.runner == :test_unit
67
+
68
+ class TestUnitEntrypointTest < Test::Unit::TestCase
69
+ def test_installs_the_dsl
70
+ assert_respond_to self.class, :with_model
71
+ end
72
+ end
73
+ RUBY
74
+ end
75
+
76
+ it "propagates Test::Unit's LoadError when the framework is unavailable" do
77
+ Dir.mktmpdir do |directory|
78
+ Dir.mkdir(File.join(directory, "test"))
79
+ File.write(
80
+ File.join(directory, "test/unit.rb"),
81
+ 'raise LoadError, "distinctive test/unit LoadError"'
82
+ )
83
+
84
+ expect_native_runner_to_pass(<<~'RUBY', load_paths: [directory, "lib"])
85
+ begin
86
+ require "with_model/test_unit"
87
+ rescue LoadError => error
88
+ abort "unexpected LoadError: #{error.message.inspect}" unless
89
+ error.message == "distinctive test/unit LoadError"
90
+ else
91
+ abort "expected a LoadError"
92
+ end
93
+ RUBY
94
+ end
95
+ end
96
+
97
+ it "retains manual Test::Unit setup with plain with_model" do
98
+ expect_native_runner_to_pass(<<~'RUBY')
99
+ require "test/unit"
100
+ require "with_model"
101
+
102
+ WithModel.runner = :test_unit
103
+ Test::Unit::TestCase.extend WithModel
104
+ abort "runner: #{WithModel.runner.inspect}" unless WithModel.runner == :test_unit
105
+
106
+ class PlainWithModelTestUnitTest < Test::Unit::TestCase
107
+ def test_installs_the_dsl
108
+ assert_respond_to self.class, :with_model
109
+ end
110
+ end
111
+ RUBY
112
+ end
113
+
114
+ it "retains manual RSpec setup with plain with_model" do
115
+ expect_native_runner_to_pass(<<~'RUBY')
116
+ require "rspec"
117
+ require "with_model"
118
+
119
+ WithModel.runner = :rspec
120
+ RSpec.configure do |config|
121
+ config.extend WithModel
122
+ end
123
+ abort "runner: #{WithModel.runner.inspect}" unless WithModel.runner == :rspec
124
+
125
+ RSpec.describe "entrypoint" do
126
+ it "installs the DSL" do
127
+ expect(self.class).to respond_to(:with_model)
128
+ end
129
+ end
130
+
131
+ exit RSpec::Core::Runner.run([])
132
+ RUBY
133
+ end
134
+
135
+ it "retains manual Minitest setup with plain with_model" do
136
+ expect_native_runner_to_pass(<<~'RUBY')
137
+ require "minitest"
138
+ require "with_model"
139
+
140
+ WithModel.runner = :minitest
141
+ Minitest::Test.extend WithModel
142
+ abort "runner: #{WithModel.runner.inspect}" unless WithModel.runner == :minitest
143
+
144
+ class PlainWithModelMinitestTest < Minitest::Test
145
+ def test_installs_the_dsl
146
+ assert_respond_to self.class, :with_model
147
+ end
148
+ end
149
+
150
+ exit(Minitest.run ? 0 : 1)
151
+ RUBY
152
+ end
153
+ end