-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't load AR integration if it is unavailable (#188)
When writing tests for a project that uses certain parts of Rails, it should still be possible to say `require "super_diff/rails"`, and SuperDiff should only load the integrations that correspond to the available parts. Right now the only two integrations are ActiveSupport and ActiveRecord. ActiveSupport should always be available, but ActiveRecord may not be available, so this commit adds a guard around that integration in particular. It also adds tests for Combustion so we can test that this guard specifically works for engines where ActiveRecord is not being loaded. Co-authored-by: Harry Lascelles <harry@harryl.com> Co-authored-by: sshaw <skye.shaw@gmail.com>
- Loading branch information
1 parent
628796a
commit 37cedd6
Showing
20 changed files
with
112 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
require "super_diff/active_record" | ||
require "super_diff/active_support" | ||
require "super_diff/active_record" if defined?(ActiveRecord) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require "spec_helper" | ||
|
||
RSpec.describe "Integration with Rails engines", type: :integration do | ||
context "when ActiveRecord is not loaded via Combustion" do | ||
it "does not fail to load" do | ||
as_both_colored_and_uncolored do |color_enabled| | ||
program = | ||
make_rspec_rails_engine_program( | ||
"expect(true).to be(true)", | ||
combustion_initialize: [:action_controller], | ||
color_enabled: color_enabled | ||
) | ||
|
||
expect(program).not_to produce_output_when_run( | ||
"uninitialized constant ActiveRecord" | ||
).in_color(color_enabled) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
spec/support/integration/test_programs/rspec_rails_engine.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module SuperDiff | ||
module IntegrationTests | ||
module TestPrograms | ||
class RspecRailsEngine < Base | ||
def initialize(*args, combustion_initialize:, **options) | ||
super(*args, **options) | ||
@combustion_initialize = combustion_initialize | ||
end | ||
|
||
protected | ||
|
||
def test_plan_prelude | ||
<<~PRELUDE.strip | ||
test_plan.boot_rails_engine( | ||
combustion_initialize: #{combustion_initialize.inspect} | ||
) | ||
PRELUDE | ||
end | ||
|
||
def test_plan_command | ||
"run_rspec_rails_test" | ||
end | ||
|
||
private | ||
|
||
attr_reader :combustion_initialize | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
"boot_rails": { | ||
"run_rspec_rails_test": [] | ||
} | ||
} | ||
}, | ||
"boot_rails_engine": [] | ||
} | ||
} |