-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a unit test for rules management
o externalize the PowerTrack configuration in a test/powertrack.yml file loaded when required, on demand
- Loading branch information
Laurent Farcy
committed
Jul 20, 2015
1 parent
6db8982
commit fc83f04
Showing
4 changed files
with
52 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,3 +37,5 @@ build/ | |
# ignore Eclipse config | ||
.project | ||
|
||
# ignore tests-related config file | ||
test/powertrack.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,31 @@ | ||
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) | ||
|
||
gem "minitest" | ||
gem 'minitest' | ||
require 'minitest/autorun' | ||
require 'yaml' | ||
|
||
class Minitest::Test | ||
|
||
POWERTRACK_CONFIG_FILEPATH = File.join(File.dirname(__FILE__), "powertrack.yml") | ||
|
||
# Returns the PowerTrack configuration as defined in test/powertrack.yml. | ||
def powertrack_config | ||
unless defined?(@loaded) && @loaded | ||
begin | ||
if File.exist?(POWERTRACK_CONFIG_FILEPATH) | ||
@pwtk_config = (YAML.load_file(POWERTRACK_CONFIG_FILEPATH) || {}) | ||
else | ||
$stderr.puts "No PowerTrack config file found at '#{POWERTRACK_CONFIG_FILEPATH}'" | ||
end | ||
rescue Exception | ||
$stderr.puts "Exception while loading PowerTrack config file: #{$!.message}" | ||
ensure | ||
@pwtk_config ||= {} | ||
end | ||
|
||
# symbolize keys | ||
@pwtk_config = Hash[@pwtk_config.map{ |k, v| [k.to_sym, v] }] | ||
@loaded = true | ||
end | ||
|
||
@pwtk_config | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters