summaryrefslogtreecommitdiff
path: root/spec/controllers/projects/environments_controller_spec.rb
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2018-11-28 17:00:11 +0100
committerYorick Peterse <yorickpeterse@gmail.com>2018-11-29 09:05:37 +0100
commit45812f1cab3431df35ec89c4d39df72f94c334f2 (patch)
tree39b02d10d393cc93ab2cf2cbb8ea79b7ed397fbc /spec/controllers/projects/environments_controller_spec.rb
parentc07183f0d3ce24e8cfcb93e71ae950d7067a8ce1 (diff)
downloadgitlab-ce-45812f1cab3431df35ec89c4d39df72f94c334f2.tar.gz
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).
Diffstat (limited to 'spec/controllers/projects/environments_controller_spec.rb')
-rw-r--r--spec/controllers/projects/environments_controller_spec.rb9
1 files changed, 7 insertions, 2 deletions
diff --git a/spec/controllers/projects/environments_controller_spec.rb b/spec/controllers/projects/environments_controller_spec.rb
index bc17331f531..5fa0488014f 100644
--- a/spec/controllers/projects/environments_controller_spec.rb
+++ b/spec/controllers/projects/environments_controller_spec.rb
@@ -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])