From 476c6045c44641db6f095a0b94a1d0b693123f5f Mon Sep 17 00:00:00 2001 From: Guillaume DOTT Date: Mon, 18 Aug 2014 10:49:35 +0200 Subject: [PATCH] Add tests --- Rakefile | 5 ++ flop.gemspec | 4 ++ test/flop/feature_test.rb | 56 ++++++++++++++++++++ test/flop/repository/generic_repo_example.rb | 13 +++++ test/flop/repository/memory_test.rb | 10 ++++ test/flop/repository/redis_test.rb | 11 ++++ test/flop_test.rb | 7 +++ test/test_helper.rb | 5 ++ 8 files changed, 111 insertions(+) create mode 100644 test/flop/feature_test.rb create mode 100644 test/flop/repository/generic_repo_example.rb create mode 100644 test/flop/repository/memory_test.rb create mode 100644 test/flop/repository/redis_test.rb create mode 100644 test/flop_test.rb create mode 100644 test/test_helper.rb diff --git a/Rakefile b/Rakefile index 809eb56..c8c9079 100644 --- a/Rakefile +++ b/Rakefile @@ -1,2 +1,7 @@ require "bundler/gem_tasks" +require 'rake/testtask' +Rake::TestTask.new do |t| + t.libs << "test" + t.test_files = Dir['test/**/*_test.rb'] +end diff --git a/flop.gemspec b/flop.gemspec index c1c8307..66bbbfe 100644 --- a/flop.gemspec +++ b/flop.gemspec @@ -20,4 +20,8 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'bundler', '~> 1.6' spec.add_development_dependency 'rake' + + spec.add_development_dependency 'minitest', '~> 5.4' + spec.add_development_dependency 'minitest-reporters' + spec.add_development_dependency 'fakeredis' end diff --git a/test/flop/feature_test.rb b/test/flop/feature_test.rb new file mode 100644 index 0000000..c1191b5 --- /dev/null +++ b/test/flop/feature_test.rb @@ -0,0 +1,56 @@ +require 'test_helper' + +class Flop::FeatureTest < Minitest::Test + def setup + @feature = Flop::Feature.new(:test) + end + + def test_it_is_inactive_by_default + assert Flop::Feature.new(:inactive_feature).inactive? + end + + def test_that_name_is_symbol + assert_equal :string, Flop::Feature.new('string').name + end + + def test_set_specified_value + @feature.set true + assert @feature.active? + + @feature.set false + assert @feature.inactive? + end + + def test_toggle + @feature.deactivate + + @feature.toggle + assert @feature.active? + end + + def test_activate + @feature.activate + assert @feature.active? + end + + def test_deactivate + @feature.deactivate + assert @feature.inactive? + end + + def test_with_executes_block + @feature.deactivate + assert_nil @feature.with { true } + + @feature.activate + assert @feature.with { true } + end + + def test_without_executes_block + @feature.deactivate + assert @feature.without { true } + + @feature.activate + assert_nil @feature.without { true } + end +end diff --git a/test/flop/repository/generic_repo_example.rb b/test/flop/repository/generic_repo_example.rb new file mode 100644 index 0000000..494018b --- /dev/null +++ b/test/flop/repository/generic_repo_example.rb @@ -0,0 +1,13 @@ +module Flop::Repository::GenericRepoExample + def test_default_value_is_false + refute @repo.get(:unknown_key), 'default value is not false' + end + + def test_get_value + @repo.set(:test, true) + @repo.set(:test2, false) + + assert_equal true, @repo.get(:test) + assert_equal false, @repo.get(:test2) + end +end diff --git a/test/flop/repository/memory_test.rb b/test/flop/repository/memory_test.rb new file mode 100644 index 0000000..1eb9969 --- /dev/null +++ b/test/flop/repository/memory_test.rb @@ -0,0 +1,10 @@ +require 'test_helper' +require 'flop/repository/generic_repo_example' + +class Flop::Repository::MemoryTest < Minitest::Test + def setup + @repo = Flop::Repository::Memory.new + end + + include Flop::Repository::GenericRepoExample +end diff --git a/test/flop/repository/redis_test.rb b/test/flop/repository/redis_test.rb new file mode 100644 index 0000000..7d4a676 --- /dev/null +++ b/test/flop/repository/redis_test.rb @@ -0,0 +1,11 @@ +require 'test_helper' +require 'flop/repository/generic_repo_example' +require 'fakeredis' + +class Flop::Repository::RedisTest < Minitest::Test + def setup + @repo = Flop::Repository::Redis.new(Redis.new) + end + + include Flop::Repository::GenericRepoExample +end diff --git a/test/flop_test.rb b/test/flop_test.rb new file mode 100644 index 0000000..e05e581 --- /dev/null +++ b/test/flop_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class FlopTest < Minitest::Test + def test_that_return_feature + assert_instance_of Flop::Feature, Flop[:test] + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb new file mode 100644 index 0000000..455e693 --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,5 @@ +require 'minitest/autorun' +require 'minitest/reporters' +Minitest::Reporters.use! [Minitest::Reporters::SpecReporter.new] + +require 'flop'