diff options
author | Abinoam Praxedes Marques Jr <abinoam@gmail.com> | 2015-02-27 12:17:29 -0300 |
---|---|---|
committer | Abinoam Praxedes Marques Jr <abinoam@gmail.com> | 2015-02-27 12:17:29 -0300 |
commit | e7ed37d5b29df1f07249a7f1472017d6f506b02b (patch) | |
tree | 421e81322f0b5b8ec4e917dabdf21fa9e18faddd | |
parent | 3def16d7ef1e048875af8144bfc1ef635edbc89d (diff) | |
download | highline-e7ed37d5b29df1f07249a7f1472017d6f506b02b.tar.gz |
Begin implementation of HighLine::Style.clear_index
There was a commented HighLine::Style.clear_index on teardown of tc_style.rb tests.
Begin implementation of it preserving builtin styles.
This is important to ensure a clean enviroment for each test.
-rwxr-xr-x | lib/highline/style.rb | 5 | ||||
-rwxr-xr-x | test/tc_style.rb | 13 |
2 files changed, 17 insertions, 1 deletions
diff --git a/lib/highline/style.rb b/lib/highline/style.rb index 3f83527..92f0b84 100755 --- a/lib/highline/style.rb +++ b/lib/highline/style.rb @@ -54,6 +54,11 @@ class HighLine style end + def self.clear_index + # reset to builtin only styles + @@styles = list.select { |name, style| style.builtin } + end + def self.rgb_hex(*colors) colors.map do |color| color.is_a?(Numeric) ? '%02x'%color : color.to_s diff --git a/test/tc_style.rb b/test/tc_style.rb index cb65878..94689a7 100755 --- a/test/tc_style.rb +++ b/test/tc_style.rb @@ -19,12 +19,23 @@ class TestStyle < Minitest::Test @style2 = HighLine::Style.new(:name=>:lando, :code=>"\e[98m") @style3 = HighLine::Style.new(:name=>[:foo, :lando], :list=>[:foo, :lando]) @style4 = HighLine::Style(:rgb_654321) + @added_styles_on_setup = 4 # update here if added more styles end def teardown - # HighLine::Style.clear_index + HighLine::Style.clear_index end + def test_clear_index_reset_styles_to_builtin + styles_size_after_setup = HighLine::Style.list.size + expected_styles_size = styles_size_after_setup - @added_styles_on_setup + + HighLine::Style.clear_index + styles_size_after_clear_index = HighLine::Style.list.size + + assert_equal expected_styles_size, styles_size_after_clear_index + end + def test_style_method # Retrieve a style from an existing Style (no new Style created) new_style = @style1.dup # This will replace @style1 in the indexes |