Skip to content

Commit

Permalink
Fix Zeus
Browse files Browse the repository at this point in the history
The Zeus config has been broken since integration tests for Rails
engines were added. It appears that the Zeus boot step responsible for
loading Combustion was passing an empty array for the modules to
initialize. Outside of Zeus, the integration test customizes this array,
but inside Zeus, that never happens, and there isn't a way to do that.
So, considering that we only have one engine-specific integration test,
I removed the customization option and hardcoded the list of modules,
renaming the boot step and corresponding command to match. I then
corrected the test accordingly.
  • Loading branch information
mcmire committed Feb 3, 2024
1 parent 32673c0 commit 5ba56d9
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 52 deletions.
8 changes: 5 additions & 3 deletions config/zeus_plan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,24 @@ class CustomZeusPlan < Zeus::Plan
:boot_active_support,
:boot_active_record,
:boot_rails,
:boot_rails_engine_with_action_controller,
:run_plain_test,
:run_rspec_active_support_test,
:run_rspec_active_record_test,
:run_rspec_rails_test
:run_rspec_rails_test,
:run_rspec_rails_engine_with_action_controller_test
)

def initialize(
using_outside_of_zeus: false,
color_enabled: false,
configuration: {}
super_diff_configuration: {}
)
@test_plan =
TestPlan.new(
using_outside_of_zeus: using_outside_of_zeus,
color_enabled: color_enabled,
configuration: configuration
super_diff_configuration: super_diff_configuration
)
end
end
Expand Down
7 changes: 5 additions & 2 deletions spec/integration/rails/engines_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
it "does not fail to load" do
as_both_colored_and_uncolored do |color_enabled|
program =
make_rspec_rails_engine_program(
make_rspec_rails_engine_with_action_controller_program(
"expect(true).to be(true)",
combustion_initialize: [:action_controller],
color_enabled: color_enabled
)

expect(program).to produce_output_when_run(
"1 example, 0 failures"
).in_color(color_enabled)

expect(program).not_to produce_output_when_run(
"uninitialized constant ActiveRecord"
).in_color(color_enabled)
Expand Down
14 changes: 6 additions & 8 deletions spec/support/integration/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ def as_both_colored_and_uncolored
def make_plain_test_program(
test,
color_enabled:,
configuration: {},
super_diff_configuration: {},
preserve_as_whole_file: false
)
TestPrograms::Plain.new(
test,
color_enabled: color_enabled,
configuration: configuration,
super_diff_configuration: super_diff_configuration,
preserve_as_whole_file: preserve_as_whole_file
)
end
Expand All @@ -32,15 +32,13 @@ def make_rspec_rails_test_program(test, color_enabled:)
TestPrograms::RSpecRails.new(test, color_enabled: color_enabled)
end

def make_rspec_rails_engine_program(
def make_rspec_rails_engine_with_action_controller_program(
test,
color_enabled:,
combustion_initialize:
color_enabled:
)
TestPrograms::RspecRailsEngine.new(
TestPrograms::RspecRailsEngineWithActionController.new(
test,
color_enabled: color_enabled,
combustion_initialize: combustion_initialize
color_enabled: color_enabled
)
end

Expand Down
12 changes: 6 additions & 6 deletions spec/support/integration/test_programs/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ class Base
def initialize(
code,
color_enabled:,
configuration: {},
super_diff_configuration: {},
preserve_as_whole_file: false
)
@code = code.strip
@color_enabled = color_enabled
@configuration = configuration
@super_diff_configuration = super_diff_configuration
@preserve_as_whole_file = preserve_as_whole_file
end

Expand All @@ -38,7 +38,7 @@ def test_plan_command

private

attr_reader :code, :configuration
attr_reader :code, :super_diff_configuration

def color_enabled?
@color_enabled
Expand Down Expand Up @@ -74,8 +74,8 @@ def command
color_option,
"--no-pry",
tempfile.to_s,
"--configuration",
JSON.generate(configuration)
"--super-diff-configuration",
JSON.generate(super_diff_configuration)
]
else
["rspec", "--options", "/tmp/dummy-rspec-config", tempfile.to_s]
Expand Down Expand Up @@ -110,7 +110,7 @@ def program
test_plan = TestPlan.new(
using_outside_of_zeus: true,
color_enabled: #{color_enabled?.inspect},
configuration: #{configuration.inspect}
super_diff_configuration: #{super_diff_configuration.inspect}
)
#{test_plan_prelude}
test_plan.#{test_plan_command}
Expand Down
2 changes: 1 addition & 1 deletion spec/support/integration/test_programs/rspec_rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class RSpecRails < Base
def test_plan_prelude
<<~PRELUDE.strip
test_plan.boot
test_plan.boot_active_record
test_plan.boot_rails
PRELUDE
end

Expand Down
16 changes: 3 additions & 13 deletions spec/support/integration/test_programs/rspec_rails_engine.rb
Original file line number Diff line number Diff line change
@@ -1,29 +1,19 @@
module SuperDiff
module IntegrationTests
module TestPrograms
class RspecRailsEngine < Base
def initialize(*args, combustion_initialize:, **options)
super(*args, **options)
@combustion_initialize = combustion_initialize
end

class RspecRailsEngineWithActionController < Base
protected

def test_plan_prelude
<<~PRELUDE.strip
test_plan.boot_rails_engine(
combustion_initialize: #{combustion_initialize.inspect}
)
test_plan.boot
test_plan.boot_rails_engine_with_action_controller
PRELUDE
end

def test_plan_command
"run_rspec_rails_test"
end

private

attr_reader :combustion_initialize
end
end
end
Expand Down
12 changes: 6 additions & 6 deletions spec/support/shared_examples/elided_diffs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
make_plain_test_program(
snippet,
color_enabled: color_enabled,
configuration: {
super_diff_configuration: {
diff_elision_enabled: true,
diff_elision_maximum: 3
}
Expand Down Expand Up @@ -129,7 +129,7 @@
make_plain_test_program(
snippet,
color_enabled: color_enabled,
configuration: {
super_diff_configuration: {
diff_elision_enabled: false,
diff_elision_maximum: 3
}
Expand Down Expand Up @@ -228,7 +228,7 @@
make_plain_test_program(
snippet,
color_enabled: color_enabled,
configuration: {
super_diff_configuration: {
diff_elision_enabled: true,
diff_elision_maximum: 3
}
Expand Down Expand Up @@ -318,7 +318,7 @@
make_plain_test_program(
snippet,
color_enabled: color_enabled,
configuration: {
super_diff_configuration: {
diff_elision_enabled: false,
diff_elision_maximum: 3
}
Expand Down Expand Up @@ -550,7 +550,7 @@
make_plain_test_program(
snippet,
color_enabled: color_enabled,
configuration: {
super_diff_configuration: {
diff_elision_enabled: true,
diff_elision_maximum: 10
}
Expand Down Expand Up @@ -811,7 +811,7 @@
make_plain_test_program(
snippet,
color_enabled: color_enabled,
configuration: {
super_diff_configuration: {
diff_elision_enabled: false,
diff_elision_maximum: 10
}
Expand Down
4 changes: 2 additions & 2 deletions spec/support/shared_examples/key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
make_plain_test_program(
snippet,
color_enabled: color_enabled,
configuration: {
super_diff_configuration: {
key_enabled: true
}
)
Expand Down Expand Up @@ -80,7 +80,7 @@
make_plain_test_program(
snippet,
color_enabled: color_enabled,
configuration: {
super_diff_configuration: {
key_enabled: false
}
)
Expand Down
23 changes: 15 additions & 8 deletions support/test_plan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ class TestPlan
def initialize(
using_outside_of_zeus: false,
color_enabled: false,
configuration: {}
super_diff_configuration: {}
)
@using_outside_of_zeus = using_outside_of_zeus
@color_enabled = color_enabled
@configuration = configuration
@super_diff_configuration = super_diff_configuration

@pry_enabled = true
@libraries = []
Expand Down Expand Up @@ -110,9 +110,11 @@ def boot_rails
boot_active_record
end

def boot_rails_engine(combustion_initialize: [])
def boot_rails_engine_with_action_controller
boot_active_support

require "combustion"
Combustion.initialize!(*combustion_initialize)
Combustion.initialize!(:action_controller)
end

def run_plain_test
Expand All @@ -131,9 +133,12 @@ def run_rspec_rails_test
run_test_with_libraries("super_diff/rspec-rails")
end

alias_method :run_rspec_rails_engine_with_action_controller_test,
:run_rspec_rails_test

private

attr_reader :libraries, :configuration
attr_reader :libraries, :super_diff_configuration

def using_outside_of_zeus?
@using_outside_of_zeus
Expand Down Expand Up @@ -165,7 +170,7 @@ def run_test_with_libraries(*libraries)
option_parser.parse! if !using_outside_of_zeus?

SuperDiff.configuration.merge!(
configuration.merge(color_enabled: color_enabled?)
super_diff_configuration.merge(color_enabled: color_enabled?)
)

ENV["DISABLE_PRY"] = "true" if !pry_enabled?
Expand All @@ -187,10 +192,12 @@ def option_parser
opts.on("--[no-]pry", "Disable Pry.") { |value| @pry_enabled = value }

opts.on(
"--configuration CONFIG",
"--super-diff-configuration CONFIG",
String,
"Configure SuperDiff."
) { |json| @configuration = JSON.parse(json).transform_keys(&:to_sym) }
) do |json|
@super_diff_configuration = JSON.parse(json).transform_keys(&:to_sym)
end
end
end
end
8 changes: 5 additions & 3 deletions zeus.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"command": "ruby -r rubygems -r ./config/zeus_plan.rb -e Zeus.go",
"plan": {
"boot": {
"run_plain_test": [],
"run_plain_test": {},
"boot_active_support": {
"run_rspec_active_support_test": []
},
Expand All @@ -11,8 +11,10 @@
},
"boot_rails": {
"run_rspec_rails_test": []
},
"boot_rails_engine_with_action_controller": {
"run_rspec_rails_engine_with_action_controller_test": []
}
},
"boot_rails_engine": []
}
}
}

0 comments on commit 5ba56d9

Please sign in to comment.