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).
This commit is contained in:
Yorick Peterse 2018-11-28 17:00:11 +01:00
parent c07183f0d3
commit 45812f1cab
No known key found for this signature in database
GPG Key ID: EDD30D2BEB691AC9
2 changed files with 15 additions and 4 deletions

View File

@ -217,7 +217,10 @@ describe Projects::EnvironmentsController do
end
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
end
@ -240,7 +243,9 @@ describe Projects::EnvironmentsController do
context 'and valid id' 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)
.and_return([:fake_terminal])

View File

@ -165,8 +165,14 @@ describe 'Environment' do
context 'web terminal', :js do
before do
# Stub #terminals as it causes js-enabled feature specs to render the page incorrectly
allow_any_instance_of(Environment).to receive(:terminals) { nil }
# Stub #terminals as it causes js-enabled feature specs to
# 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)
end