Commit 45812f1c authored by Yorick Peterse's avatar Yorick Peterse

Fix Environment terminal specs for EE

In EE we redefine Environment#terminals, which makes it impossible to
use `allow_any_instance_of(Environment)` or
`expect_any_instance_of(Environment)`. Other approaches of stubbing
this class, such as by stubbing `new`, only result in spec failures.

To solve this issue, we add a simple `defined?(EE)` check in the tests
to change the thing that we are testing. This is rather obnoxious,
because it requires EE knowledge in CE, and can break if
`EE::Environment` is removed without updating CE. Unfortunately, it
appears to be the only solution we have apart from modifying these tests
in EE (which would cause merge conflicts).
parent c07183f0
...@@ -217,7 +217,10 @@ describe Projects::EnvironmentsController do ...@@ -217,7 +217,10 @@ describe Projects::EnvironmentsController do
end end
it 'loads the terminals for the environment' do it 'loads the terminals for the environment' do
expect_any_instance_of(Environment).to receive(:terminals) # In EE we have to stub EE::Environment since it overwrites the
# "terminals" method.
expect_any_instance_of(defined?(EE) ? EE::Environment : Environment)
.to receive(:terminals)
get :terminal, environment_params get :terminal, environment_params
end end
...@@ -240,7 +243,9 @@ describe Projects::EnvironmentsController do ...@@ -240,7 +243,9 @@ describe Projects::EnvironmentsController do
context 'and valid id' do context 'and valid id' do
it 'returns the first terminal for the environment' do it 'returns the first terminal for the environment' do
expect_any_instance_of(Environment) # In EE we have to stub EE::Environment since it overwrites the
# "terminals" method.
expect_any_instance_of(defined?(EE) ? EE::Environment : Environment)
.to receive(:terminals) .to receive(:terminals)
.and_return([:fake_terminal]) .and_return([:fake_terminal])
......
...@@ -165,8 +165,14 @@ describe 'Environment' do ...@@ -165,8 +165,14 @@ describe 'Environment' do
context 'web terminal', :js do context 'web terminal', :js do
before do before do
# Stub #terminals as it causes js-enabled feature specs to render the page incorrectly # Stub #terminals as it causes js-enabled feature specs to
allow_any_instance_of(Environment).to receive(:terminals) { nil } # render the page incorrectly
#
# In EE we have to stub EE::Environment since it overwrites
# the "terminals" method.
allow_any_instance_of(defined?(EE) ? EE::Environment : Environment)
.to receive(:terminals) { nil }
visit terminal_project_environment_path(project, environment) visit terminal_project_environment_path(project, environment)
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment