File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed
lib/code_climate/test_reporter Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -58,7 +58,7 @@ def configured_git_dir
58
58
end
59
59
60
60
def rails_git_dir_present?
61
- defined? ( Rails ) && !Rails . root . nil? &&
61
+ const_defined? ( : Rails) && Rails . respond_to? ( :root ) && !Rails . root . nil? &&
62
62
File . directory? ( File . expand_path ( '.git' , Rails . root ) )
63
63
end
64
64
end
Original file line number Diff line number Diff line change @@ -22,7 +22,40 @@ module CodeClimate::TestReporter
22
22
expect ( Git ) . to receive ( :` ) . once . with "git --git-dir=\" #{ path } /.git\" help"
23
23
24
24
Git . send :git , 'help'
25
+ end
26
+
27
+ context 'ensure logic that replies on Rails is robust in non-rails environments' do
28
+ before :all do
29
+ module ::Rails ; end
30
+ end
31
+
32
+ after :all do
33
+ Object . send ( :remove_const , :Rails )
25
34
end
35
+
36
+ after :each do
37
+ Git . send :git , 'help'
38
+ end
39
+
40
+ it 'will check if constant Rails is defined' do
41
+ expect ( Git ) . to receive ( :configured_git_dir ) . once . and_return ( nil )
42
+ end
43
+
44
+ it 'will not call method "root" (a 3rd time) if constant Rails is defined but does not respond to root' do
45
+ expect ( Git ) . to receive ( :configured_git_dir ) . once . and_return ( nil )
46
+ expect ( Rails ) . to receive ( :root ) . twice . and_return ( '/path' )
47
+ end
48
+
49
+ it 'will call rails root if constant Rails is defined and root method is defined' do
50
+ module ::Rails
51
+ def self . root
52
+ '/path'
53
+ end
54
+ end
55
+ expect ( Git ) . to receive ( :configured_git_dir ) . once . and_return ( nil )
56
+ expect ( Rails ) . to receive ( :root ) . twice . and_return ( '/path' )
57
+ end
58
+ end
26
59
end
27
60
28
61
describe 'branch_from_git_or_ci' do
You can’t perform that action at this time.
0 commit comments