-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add some unit tests for new rake tasks
- Loading branch information
Showing
2 changed files
with
67 additions
and
8 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
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
require File.expand_path('../../../../test_helper', __FILE__) | ||
require File.expand_path('../../../../../lib/tasks/support/methods', __FILE__) | ||
|
||
describe Flipflop::Rake::SupportMethods do | ||
subject do | ||
object = Object.new | ||
object.extend Flipflop::Rake::SupportMethods | ||
end | ||
|
||
describe '#status_label' do | ||
it 'returns the "enabled" label when its argument is "true"' do | ||
assert_equal 'ON', subject.status_label(true) | ||
end | ||
|
||
it 'returns the "disabled" label when its argument is "false"' do | ||
assert_equal 'OFF', subject.status_label(false) | ||
end | ||
|
||
it 'returns the "unset" label when its argument is "nil"' do | ||
assert_equal '', subject.status_label(nil) | ||
end | ||
end | ||
|
||
describe '#switch_feature!' do | ||
def with_feature_and_strategy | ||
# Stubs finder methods to avoid going into FeatureSet code. | ||
feature = Flipflop::FeatureDefinition.new(:world_domination) | ||
subject.stub :find_feature_by_name, feature do | ||
strategy = Flipflop::Strategies::TestStrategy.new(name: 'test') | ||
subject.stub :find_strategy_by_name, strategy do | ||
yield(strategy, feature) if block_given? | ||
end | ||
end | ||
end | ||
|
||
it 'enables a feature using a strategy' do | ||
with_feature_and_strategy do |strategy, feature| | ||
subject.switch_feature! 'world_domination', 'test', true | ||
assert_equal true, strategy.enabled?(feature.key) | ||
end | ||
end | ||
|
||
it 'disables a feature using a strategy' do | ||
with_feature_and_strategy do |strategy, feature| | ||
subject.switch_feature! 'world_domination', 'test', false | ||
assert_equal false, strategy.enabled?(feature.key) | ||
end | ||
end | ||
|
||
it 'clears a feature using a strategy' do | ||
with_feature_and_strategy do |strategy, feature| | ||
subject.clear_feature! 'world_domination', 'test' | ||
assert_nil strategy.enabled?(feature.key) | ||
end | ||
end | ||
end | ||
end |