Skip to content

Commit

Permalink
Merge pull request #54 from davidrunger/dont-look-for-config-file-in-…
Browse files Browse the repository at this point in the history
…tests

Stub `ConfigFileOptions#config_file_exists?` to return false in tests
  • Loading branch information
davidrunger authored Jun 6, 2020
2 parents 6d921d2 + f712a71 commit 0d3c09c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Unreleased
### Tests
- Stub `ConfigFileOptions#config_file_exists?` to return `false` in tests

## 0.2.17 - 2020-06-05
### Fixed
- Print warning about missing `.fcom.yml` config file before executing querier
Expand Down
16 changes: 14 additions & 2 deletions lib/fcom/config_file_options.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# frozen_string_literal: true

class Fcom::ConfigFileOptions
extend Memoist

def initialize
config_file_path = "#{ENV['PWD']}/.fcom.yml"
@options =
if File.exist?(config_file_path)
if config_file_exists?
YAML.load_file(config_file_path)
else
{}
Expand All @@ -14,4 +15,15 @@ def initialize
def repo
@options['repo']
end

private

memoize \
def config_file_path
"#{ENV['PWD']}/.fcom.yml"
end

def config_file_exists?
File.exist?(config_file_path)
end
end
5 changes: 5 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@

# stub this method in all tests because otherwise it calls `git remote ...` which is really slow
allow_any_instance_of(Fcom::GitHelpers).to receive(:repo).and_return('testuser/testrepo')

# pretend that `.fcom.yml` doesn't exist in tests
allow_any_instance_of(Fcom::ConfigFileOptions).
to receive(:config_file_exists?).
and_return(false)
end

config.after(:each) do |example|
Expand Down

0 comments on commit 0d3c09c

Please sign in to comment.