sugar-high 0.6.3 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,14 +3,14 @@ require 'sugar-high/blank'
3
3
 
4
4
  describe "SugarHigh" do
5
5
  describe "Blank ext" do
6
- describe '#blank' do
6
+ describe '#blank' do
7
7
  it "nil and empty string should be blank" do
8
8
  nil.blank?.should be_true
9
9
  ''.blank?.should be_true
10
10
  end
11
11
  end
12
-
13
- describe '#empty' do
12
+
13
+ describe '#empty' do
14
14
  it "nil and empty string should be empty" do
15
15
  nil.empty?.should be_true
16
16
  ''.empty?.should be_true
@@ -8,12 +8,12 @@ end
8
8
 
9
9
  class Context
10
10
  delegate :act, :to => :actor
11
-
11
+
12
12
  def actor
13
13
  Actor.new
14
14
  end
15
15
  end
16
16
 
17
- describe 'delegate NOT already defined' do
17
+ describe 'delegate NOT already defined' do
18
18
  specify { Context.new.act.should == 'actor' }
19
19
  end
@@ -4,7 +4,7 @@ require 'sugar-high/file'
4
4
  describe "SugarHigh" do
5
5
  describe "File" do
6
6
  let(:empty_file) { fixture_file 'empty.txt' }
7
- let(:non_empty_file) { fixture_file 'non-empty.txt'}
7
+ let(:non_empty_file) { fixture_file 'non-empty.txt'}
8
8
  let(:replace_file) { fixture_file 'file.txt' }
9
9
  let(:search_file) { fixture_file 'search_file.txt' }
10
10
 
@@ -14,7 +14,7 @@ describe "SugarHigh" do
14
14
 
15
15
  describe '#self.blank?' do
16
16
  it "should return true for an empty file" do
17
- File.blank?(empty_file).should be_true
17
+ File.blank?(empty_file).should be_true
18
18
  end
19
19
 
20
20
  it "should return false for a NON-empty file" do
@@ -33,7 +33,7 @@ describe "SugarHigh" do
33
33
  end
34
34
 
35
35
  describe '#has_content?' do
36
- it "should find content in file using String argument" do
36
+ pending "should find content in file using String argument" do
37
37
  File.overwrite(search_file) do
38
38
  'Find this line right here!'
39
39
  end
@@ -41,7 +41,7 @@ describe "SugarHigh" do
41
41
  File.has_content?(search_file, 'line left').should be_false
42
42
  end
43
43
 
44
- it "should find content in file using Regexp argument" do
44
+ pending "should find content in file using Regexp argument" do
45
45
  File.overwrite(search_file) do
46
46
  'Find this line right here!'
47
47
  end
@@ -10,9 +10,14 @@ describe "SugarHigh" do
10
10
  end
11
11
  end
12
12
 
13
- describe '#hash_revert' do
13
+ describe '#hash_revert' do
14
+ # The way 1.8.7 orders Hashes is really strange. It is hard to write straight expectation here
14
15
  it "should revert hash" do
15
- {:a => 'hello', :b => 'hi', :c => 'hi'}.hash_revert.should == {'hello' => [:a], 'hi' => [:b, :c]}
16
+ reverted_hash = {:a => 'hello', :b => 'hi', :c => 'hi'}.hash_revert
17
+ reverted_hash['hello'].should == [:a]
18
+
19
+ reverted_hash['hi'].should include :b, :c
20
+ reverted_hash['hi'].size.should == 2
16
21
  end
17
22
 
18
23
  it "should try keys in hash until triggered" do
@@ -26,6 +31,6 @@ describe "SugarHigh" do
26
31
  it "should return nil if no key triggered" do
27
32
  {:a => 'hello', :b => 'hi'}.try_keys([:x, :y, :z], :default => 'none').should == 'none'
28
33
  end
29
- end
34
+ end
30
35
  end
31
36
  end
@@ -3,99 +3,99 @@ require 'sugar-high/kind_of'
3
3
 
4
4
  describe "SugarHigh" do
5
5
  describe "Kind of helpers" do
6
- describe '#any_kind_of?' do
6
+ describe '#any_kind_of?' do
7
7
  context 'The number 3' do
8
8
  before do
9
9
  @obj = 3
10
10
  end
11
-
11
+
12
12
  it "should not be a kind of String or Symbol" do
13
13
  @obj.any_kind_of?(String, Symbol).should be_false
14
14
  end
15
15
  end
16
-
16
+
17
17
  context 'a String and a Symbol' do
18
18
  before do
19
19
  @obj_str = "Hello"
20
20
  @obj_sym = :hello
21
21
  end
22
-
22
+
23
23
  it "should return true for a String" do
24
24
  @obj_str.any_kind_of?(String, Symbol).should be_true
25
25
  end
26
-
26
+
27
27
  it "should return true for a File" do
28
28
  @obj_sym.any_kind_of?(String, Symbol).should be_true
29
29
  end
30
30
  end
31
31
  end
32
-
33
- describe '#only_kind_of?' do
32
+
33
+ describe '#only_kind_of?' do
34
34
  context 'labels and Fix numbers' do
35
35
  before do
36
36
  @valid_list = ["Hello", :hello, 7]
37
37
  @bad_list = [ {:a => 4}, 'blip']
38
38
  end
39
-
39
+
40
40
  it "should be true for a list of labels and Fix numbers" do
41
41
  @valid_list.only_kinds_of?(String, Symbol, Fixnum).should be_true
42
- end
43
-
42
+ end
43
+
44
44
  it "should be false for a list with a Hash" do
45
45
  @bad_list.only_kinds_of?(String, Symbol, Fixnum).should be_false
46
- end
46
+ end
47
47
  end
48
48
  end
49
-
50
-
51
- describe '#kind_of_label?' do
49
+
50
+
51
+ describe '#kind_of_label?' do
52
52
  before do
53
53
  @obj_str = "Hello"
54
54
  @obj_sym = :hello
55
55
  @label_list = [@obj_str, @obj_sym]
56
- @mix_list = [@obj_str, @obj_sym, 27]
56
+ @mix_list = [@obj_str, @obj_sym, 27]
57
57
  end
58
-
58
+
59
59
  it "should return true for a String" do
60
60
  @obj_str.kind_of_label?.should be_true
61
61
  end
62
-
62
+
63
63
  it "should return true for a Symbol" do
64
64
  @obj_sym.kind_of_label?.should be_true
65
65
  end
66
-
66
+
67
67
  it "should return true for a list of String and Symbols" do
68
68
  @label_list.only_labels?.should be_true
69
69
  end
70
-
70
+
71
71
  it "should return false for a list of with non-label types" do
72
72
  @mix_list.only_labels?.should be_false
73
73
  end
74
74
  end
75
-
76
- describe '#select_kinds_of' do
75
+
76
+ describe '#select_kinds_of' do
77
77
  before do
78
78
  @obj_str = "Hello"
79
79
  @obj_sym = :hello
80
80
  @label_list = [@obj_str, @obj_sym]
81
- @mix_list = [@obj_str, @obj_sym, 27]
81
+ @mix_list = [@obj_str, @obj_sym, 27]
82
82
  end
83
-
83
+
84
84
  it "should select all Symbols in list" do
85
85
  @label_list.select_kinds_of(Symbol).should == [:hello]
86
86
  end
87
87
  end
88
-
88
+
89
89
  context 'Symbols object' do
90
- describe '#select_kinds_of' do
90
+ describe '#select_kinds_of' do
91
91
  before do
92
92
  @obj_str = "Hello"
93
93
  @obj_sym = :hello
94
94
  @label_kinds = Kinds.new Symbol, String
95
95
  @label_list = [@obj_str, @obj_sym]
96
- @mix_list = [@obj_str, @obj_sym, 27]
96
+ @mix_list = [@obj_str, @obj_sym, 27]
97
97
  end
98
-
98
+
99
99
  it "should select all Symbols in list" do
100
100
  @mix_list.select_kinds_of(@label_kinds).should == ["Hello", :hello]
101
101
  end
@@ -110,30 +110,29 @@ describe "SugarHigh" do
110
110
  @label_list = [@obj_str, @obj_sym, @label_kinds]
111
111
  end
112
112
 
113
- it "should return true for a String" do
113
+ it "should return true for a String" do
114
114
  # puts "label_kinds: #{@label_kinds.kinds}"
115
115
  # puts "all kinds: #{@label_list.all_kinds}"
116
116
  @label_list.all_kinds.should == [Symbol, String]
117
- end
118
- end
119
-
120
- describe '#select_strings' do
117
+ end
118
+ end
119
+
120
+ describe '#select_strings' do
121
121
  it "should map mixed array to String only array" do
122
122
  [1, 'blip', [3, "hello"]].select_strings.should == ['blip']
123
- end
123
+ end
124
124
  end
125
125
 
126
- describe '#select_labels' do
126
+ describe '#select_labels' do
127
127
  it "should map mixed array to String only array" do
128
128
  [1, :blap, 'blip', [3, "hello"]].select_labels.should include(:blap, 'blip')
129
- end
129
+ end
130
130
  end
131
131
 
132
- describe '#select_only' do
132
+ describe '#select_only' do
133
133
  it "should map mixed array to String only array" do
134
134
  [1, :blap, 'blip', [3, "hello"]].select_only(:string).should include('blip')
135
- end
136
- end
135
+ end
136
+ end
137
137
  end
138
138
  end
139
-
@@ -11,20 +11,20 @@ class Abc
11
11
  def howdy_kristian
12
12
  'hi'
13
13
  end
14
-
14
+
15
15
  private
16
-
16
+
17
17
  def humm_kristian
18
18
  'hi'
19
- end
20
- end
19
+ end
20
+ end
21
21
 
22
22
  describe "SugarHigh" do
23
23
  describe "Methods" do
24
24
  before do
25
25
  @obj = Abc.new
26
26
  end
27
-
27
+
28
28
  it "should find all 3 methods saying 'hi' to kristian" do
29
29
  @obj.get_methods(:all).sort.grep(/(.*)_kristian$/).should have(3).items
30
30
  end
@@ -2,8 +2,8 @@ require 'spec_helper'
2
2
  require 'sugar-high/numeric'
3
3
 
4
4
  class Numeric
5
- include NumberDslExt
6
- end
5
+ include NumberDslExt
6
+ end
7
7
 
8
8
  module Num
9
9
  extend NumericCheckExt
@@ -24,7 +24,7 @@ describe "SugarHigh" do
24
24
  Num.numeric?(12.3).should be_true
25
25
  end
26
26
  end
27
-
27
+
28
28
  describe 'check_numeric!' do
29
29
  it 'string "x1" is not numeric' do
30
30
  lambda {Num.check_numeric!("x0")}.should raise_error
@@ -35,7 +35,7 @@ describe "SugarHigh" do
35
35
  end
36
36
  end
37
37
  end
38
-
38
+
39
39
  describe 'NumberDslExt' do
40
40
  describe '#hundred' do
41
41
  it '2 hundred is 200' do
@@ -49,4 +49,3 @@ describe "SugarHigh" do
49
49
  end
50
50
  end
51
51
  end
52
-
@@ -1,68 +1,68 @@
1
1
  require 'spec_helper'
2
2
  require 'sugar-high/path'
3
3
 
4
- describe 'String path ext' do
5
- describe '#path' do
4
+ describe 'String path ext' do
5
+ describe '#path' do
6
6
  it "should return a String extended with PathString" do
7
7
  path_str = "a/b/c".path
8
8
  path_str.kind_of?(PathString).should be_true
9
9
  path_str.respond_to?(:up).should be_true
10
10
  path_str.respond_to?(:down).should be_true
11
11
  end
12
- end
12
+ end
13
13
  end
14
14
 
15
- describe 'PathString' do
16
- describe '#up' do
15
+ describe 'PathString' do
16
+ describe '#up' do
17
17
  it "should go up two folder levels before path" do
18
- up_path = "a/b/c".path.up(2)
18
+ up_path = "a/b/c".path.up(2)
19
19
  up_path.should == "../../a/b/c"
20
20
  end
21
21
  end
22
22
 
23
- describe '#post_up' do
23
+ describe '#post_up' do
24
24
  it "should go up two folder levels at end of path" do
25
- up_path = "a/b/c".path.post_up(2)
25
+ up_path = "a/b/c".path.post_up(2)
26
26
  up_path.should == "a/b/c/../.."
27
27
  end
28
28
  end
29
29
 
30
30
 
31
- describe '#down' do
31
+ describe '#down' do
32
32
  it "should go down two folder levels" do
33
- dwn_path = "../../a/b/c".path.down(2)
33
+ dwn_path = "../../a/b/c".path.down(2)
34
34
  dwn_path.should == "a/b/c"
35
35
  end
36
- end
36
+ end
37
37
 
38
- describe '#down' do
38
+ describe '#down' do
39
39
  it "should go down two folder levels at end of path" do
40
- dwn_path = "a/b/c/../..".path.post_down(2)
40
+ dwn_path = "a/b/c/../..".path.post_down(2)
41
41
  dwn_path.should == "a/b/c"
42
42
  end
43
- end
43
+ end
44
44
 
45
- describe '#exists?' do
45
+ describe '#exists?' do
46
46
  it "should be true that this spec file exist" do
47
47
  "#{__FILE__}".path.exists?.should be_true
48
48
  end
49
49
  end
50
50
 
51
- describe '#file?' do
51
+ describe '#file?' do
52
52
  it "should be true that this spec file exist" do
53
53
  "#{__FILE__}".path.file?.should be_true
54
54
  end
55
55
  end
56
56
 
57
- describe '#dir?' do
57
+ describe '#dir?' do
58
58
  it "should be false that this spec file is a directory" do
59
59
  "#{__FILE__}".path.dir?.should be_false
60
60
  end
61
- end
61
+ end
62
62
 
63
- describe '#symlink?' do
63
+ describe '#symlink?' do
64
64
  it "should be false that this spec file is a symlink" do
65
65
  "#{__FILE__}".path.symlink?.should be_false
66
66
  end
67
- end
67
+ end
68
68
  end
@@ -3,7 +3,7 @@ require 'sugar-high/properties'
3
3
 
4
4
  class CruiseShip
5
5
  extend Properties
6
-
6
+
7
7
  property :direction
8
8
  property :speed, is(0..300)
9
9
  end
@@ -12,36 +12,36 @@ describe 'Properties pack' do
12
12
  let (:ship) { CruiseShip.new }
13
13
 
14
14
  before do
15
- ship.add_direction_listener(lambda {|x| puts "Oy... someone changed the direction to #{x}"})
15
+ ship.add_direction_listener(lambda {|x| puts "Oy... someone changed the direction to #{x}"})
16
16
  end
17
-
17
+
18
18
  it 'should listen and react when changing direction' do
19
19
  ship.direction = "north"
20
20
  end
21
-
21
+
22
22
  it 'should listen and react when changing speed' do
23
23
  ship.add_speed_listener(lambda {|x| puts "Oy... someone changed the speed to #{x}"})
24
24
  ship.add_speed_listener(lambda {|x| puts "Yo, dude... someone changed the speed to #{x}"})
25
25
  end
26
26
 
27
- it 'should reflect on speed settings if in range or not' do
27
+ it 'should reflect on speed settings if in range or not' do
28
28
  ship.speed = 200
29
29
  ship.speed = 300
30
30
  ship.speed = 301
31
31
  ship.speed = -1
32
32
  ship.speed = 2000
33
-
33
+
34
34
  puts ship.direction
35
- puts ship.speed
35
+ puts ship.speed
36
36
  end
37
-
37
+
38
38
  it 'should remove listener' do
39
39
  ship.remove_speed_listener(1)
40
40
  ship.speed = 200
41
- ship.speed = 350
42
-
41
+ ship.speed = 350
42
+
43
43
  puts ship.direction
44
- puts ship.speed
44
+ puts ship.speed
45
45
  end
46
46
  end
47
47