mspec 1.5.9 → 1.5.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/Rakefile +1 -1
  2. data/lib/mspec/commands/mspec-ci.rb +5 -1
  3. data/lib/mspec/commands/mspec-run.rb +8 -5
  4. data/lib/mspec/guards/background.rb +2 -0
  5. data/lib/mspec/guards/bug.rb +5 -1
  6. data/lib/mspec/guards/compliance.rb +10 -0
  7. data/lib/mspec/guards/conflict.rb +2 -0
  8. data/lib/mspec/guards/endian.rb +4 -0
  9. data/lib/mspec/guards/extensions.rb +2 -0
  10. data/lib/mspec/guards/guard.rb +49 -25
  11. data/lib/mspec/guards/noncompliance.rb +2 -0
  12. data/lib/mspec/guards/platform.rb +5 -0
  13. data/lib/mspec/guards/quarantine.rb +2 -0
  14. data/lib/mspec/guards/runner.rb +4 -0
  15. data/lib/mspec/guards/superuser.rb +2 -0
  16. data/lib/mspec/guards/support.rb +2 -0
  17. data/lib/mspec/guards/tty.rb +2 -0
  18. data/lib/mspec/guards/version.rb +3 -0
  19. data/lib/mspec/matchers.rb +1 -0
  20. data/lib/mspec/matchers/have_constant.rb +30 -0
  21. data/lib/mspec/matchers/method.rb +4 -3
  22. data/lib/mspec/matchers/stringsymboladapter.rb +8 -0
  23. data/lib/mspec/runner/actions/tally.rb +13 -3
  24. data/lib/mspec/runner/context.rb +8 -1
  25. data/lib/mspec/runner/mspec.rb +16 -0
  26. data/lib/mspec/utils/options.rb +10 -3
  27. data/lib/mspec/version.rb +1 -1
  28. data/spec/guards/background_spec.rb +15 -0
  29. data/spec/guards/bug_spec.rb +28 -10
  30. data/spec/guards/compliance_spec.rb +54 -0
  31. data/spec/guards/conflict_spec.rb +19 -0
  32. data/spec/guards/endian_spec.rb +26 -0
  33. data/spec/guards/extensions_spec.rb +20 -0
  34. data/spec/guards/guard_spec.rb +69 -52
  35. data/spec/guards/noncompliance_spec.rb +20 -0
  36. data/spec/guards/platform_spec.rb +26 -0
  37. data/spec/guards/quarantine_spec.rb +16 -0
  38. data/spec/guards/runner_spec.rb +26 -0
  39. data/spec/guards/superuser_spec.rb +13 -0
  40. data/spec/guards/support_spec.rb +20 -0
  41. data/spec/guards/tty_spec.rb +16 -0
  42. data/spec/guards/version_spec.rb +13 -0
  43. data/spec/matchers/have_constant_spec.rb +37 -0
  44. data/spec/matchers/stringsymboladapter_spec.rb +40 -0
  45. data/spec/runner/actions/tagpurge_spec.rb +1 -0
  46. data/spec/runner/actions/tally_spec.rb +64 -0
  47. data/spec/runner/context_spec.rb +24 -11
  48. data/spec/runner/formatters/html_spec.rb +1 -0
  49. data/spec/runner/mspec_spec.rb +31 -0
  50. data/spec/utils/options_spec.rb +59 -0
  51. metadata +6 -3
  52. data/spec/matchers/method_spec.rb +0 -36
@@ -47,3 +47,23 @@ describe Object, "#deviates_on" do
47
47
  ScratchPad.recorded.should == :yield
48
48
  end
49
49
  end
50
+
51
+ describe Object, "#deviates_on" do
52
+ before :each do
53
+ @guard = NonComplianceGuard.new
54
+ NonComplianceGuard.stub!(:new).and_return(@guard)
55
+ end
56
+
57
+ it "sets the name of the guard to :deviates_on" do
58
+ deviates_on(:jruby) { }
59
+ @guard.name.should == :deviates_on
60
+ end
61
+
62
+ it "calls #unregister even when an exception is raised in the guard block" do
63
+ @guard.should_receive(:match?).and_return(true)
64
+ @guard.should_receive(:unregister)
65
+ lambda do
66
+ deviates_on(:rubinius) { raise Exception }
67
+ end.should raise_error(Exception)
68
+ end
69
+ end
@@ -19,6 +19,19 @@ describe Object, "#platform_is" do
19
19
  platform_is(:solarce) { ScratchPad.record :yield }
20
20
  ScratchPad.recorded.should == :yield
21
21
  end
22
+
23
+ it "sets the name of the guard to :platform_is" do
24
+ platform_is(:solarce) { }
25
+ @guard.name.should == :platform_is
26
+ end
27
+
28
+ it "calls #unregister even when an exception is raised in the guard block" do
29
+ @guard.should_receive(:match?).and_return(true)
30
+ @guard.should_receive(:unregister)
31
+ lambda do
32
+ platform_is(:solarce) { raise Exception }
33
+ end.should raise_error(Exception)
34
+ end
22
35
  end
23
36
 
24
37
  describe Object, "#platform_is_not" do
@@ -39,6 +52,19 @@ describe Object, "#platform_is_not" do
39
52
  platform_is_not(:solarce) { ScratchPad.record :yield }
40
53
  ScratchPad.recorded.should == :yield
41
54
  end
55
+
56
+ it "sets the name of the guard to :platform_is_not" do
57
+ platform_is_not(:solarce) { }
58
+ @guard.name.should == :platform_is_not
59
+ end
60
+
61
+ it "calls #unregister even when an exception is raised in the guard block" do
62
+ @guard.should_receive(:match?).and_return(false)
63
+ @guard.should_receive(:unregister)
64
+ lambda do
65
+ platform_is_not(:solarce) { raise Exception }
66
+ end.should raise_error(Exception)
67
+ end
42
68
  end
43
69
 
44
70
  describe Object, "#platform_is :wordsize => SIZE_SPEC" do
@@ -10,10 +10,26 @@ end
10
10
  describe Object, "#quarantine!" do
11
11
  before :each do
12
12
  ScratchPad.clear
13
+
14
+ @guard = QuarantineGuard.new
15
+ QuarantineGuard.stub!(:new).and_return(@guard)
13
16
  end
14
17
 
15
18
  it "does not yield" do
16
19
  quarantine! { ScratchPad.record :yield }
17
20
  ScratchPad.recorded.should_not == :yield
18
21
  end
22
+
23
+ it "sets the name of the guard to :quarantine!" do
24
+ quarantine! { }
25
+ @guard.name.should == :quarantine!
26
+ end
27
+
28
+ it "calls #unregister even when an exception is raised in the guard block" do
29
+ @guard.should_receive(:match?).and_return(true)
30
+ @guard.should_receive(:unregister)
31
+ lambda do
32
+ quarantine! { raise Exception }
33
+ end.should raise_error(Exception)
34
+ end
19
35
  end
@@ -52,6 +52,19 @@ describe Object, "#runner_is" do
52
52
  runner_is(:mspec) { ScratchPad.record :yield }
53
53
  ScratchPad.recorded.should_not == :yield
54
54
  end
55
+
56
+ it "sets the name of the guard to :runner_is" do
57
+ runner_is(:mspec) { }
58
+ @guard.name.should == :runner_is
59
+ end
60
+
61
+ it "calls #unregister even when an exception is raised in the guard block" do
62
+ @guard.should_receive(:match?).and_return(true)
63
+ @guard.should_receive(:unregister)
64
+ lambda do
65
+ runner_is(:mspec) { raise Exception }
66
+ end.should raise_error(Exception)
67
+ end
55
68
  end
56
69
 
57
70
  describe Object, "#runner_is_not" do
@@ -72,4 +85,17 @@ describe Object, "#runner_is_not" do
72
85
  runner_is_not(:mspec) { ScratchPad.record :yield }
73
86
  ScratchPad.recorded.should == :yield
74
87
  end
88
+
89
+ it "sets the name of the guard to :runner_is_not" do
90
+ runner_is_not(:mspec) { }
91
+ @guard.name.should == :runner_is_not
92
+ end
93
+
94
+ it "calls #unregister even when an exception is raised in the guard block" do
95
+ @guard.should_receive(:match?).and_return(false)
96
+ @guard.should_receive(:unregister)
97
+ lambda do
98
+ runner_is_not(:mspec) { raise Exception }
99
+ end.should raise_error(Exception)
100
+ end
75
101
  end
@@ -19,4 +19,17 @@ describe Object, "#as_superuser" do
19
19
  as_superuser { ScratchPad.record :yield }
20
20
  ScratchPad.recorded.should == :yield
21
21
  end
22
+
23
+ it "sets the name of the guard to :as_superuser" do
24
+ as_superuser { }
25
+ @guard.name.should == :as_superuser
26
+ end
27
+
28
+ it "calls #unregister even when an exception is raised in the guard block" do
29
+ @guard.should_receive(:match?).and_return(true)
30
+ @guard.should_receive(:unregister)
31
+ lambda do
32
+ as_superuser { raise Exception }
33
+ end.should raise_error(Exception)
34
+ end
22
35
  end
@@ -47,3 +47,23 @@ describe Object, "#not_supported_on" do
47
47
  ScratchPad.recorded.should == :yield
48
48
  end
49
49
  end
50
+
51
+ describe Object, "#not_supported_on" do
52
+ before :each do
53
+ @guard = SupportedGuard.new
54
+ SupportedGuard.stub!(:new).and_return(@guard)
55
+ end
56
+
57
+ it "sets the name of the guard to :not_supported_on" do
58
+ not_supported_on(:rubinius) { }
59
+ @guard.name.should == :not_supported_on
60
+ end
61
+
62
+ it "calls #unregister even when an exception is raised in the guard block" do
63
+ @guard.should_receive(:match?).and_return(true)
64
+ @guard.should_receive(:unregister)
65
+ lambda do
66
+ not_supported_on(:rubinius) { raise Exception }
67
+ end.should raise_error(Exception)
68
+ end
69
+ end
@@ -4,6 +4,9 @@ require 'mspec/guards/tty'
4
4
  describe Object, "#with_tty" do
5
5
  before :each do
6
6
  ScratchPad.clear
7
+
8
+ @guard = TTYGuard.new
9
+ TTYGuard.stub!(:new).and_return(@guard)
7
10
  end
8
11
 
9
12
  it "yields if STDOUT is a TTY" do
@@ -17,4 +20,17 @@ describe Object, "#with_tty" do
17
20
  with_tty { ScratchPad.record :yield }
18
21
  ScratchPad.recorded.should_not == :yield
19
22
  end
23
+
24
+ it "sets the name of the guard to :with_tty" do
25
+ with_tty { }
26
+ @guard.name.should == :with_tty
27
+ end
28
+
29
+ it "calls #unregister even when an exception is raised in the guard block" do
30
+ @guard.should_receive(:match?).and_return(true)
31
+ @guard.should_receive(:unregister)
32
+ lambda do
33
+ with_tty { raise Exception }
34
+ end.should raise_error(Exception)
35
+ end
20
36
  end
@@ -114,4 +114,17 @@ describe Object, "#ruby_version_is" do
114
114
  ruby_version_is('x.x.x.x') { ScratchPad.record :yield }
115
115
  ScratchPad.recorded.should_not == :yield
116
116
  end
117
+
118
+ it "sets the name of the guard to :ruby_version_is" do
119
+ ruby_version_is("") { }
120
+ @guard.name.should == :ruby_version_is
121
+ end
122
+
123
+ it "calls #unregister even when an exception is raised in the guard block" do
124
+ @guard.should_receive(:match?).and_return(true)
125
+ @guard.should_receive(:unregister)
126
+ lambda do
127
+ ruby_version_is("") { raise Exception }
128
+ end.should raise_error(Exception)
129
+ end
117
130
  end
@@ -0,0 +1,37 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'mspec/expectations/expectations'
3
+ require 'mspec/matchers/have_constant'
4
+
5
+ class HCMSpecs
6
+ X = :x
7
+ end
8
+
9
+ describe HaveConstantMatcher do
10
+ it "matches when mod has the constant" do
11
+ matcher = HaveConstantMatcher.new :X
12
+ matcher.matches?(HCMSpecs).should be_true
13
+ end
14
+
15
+ it "does not match when mod does not have the constant" do
16
+ matcher = HaveConstantMatcher.new :A
17
+ matcher.matches?(HCMSpecs).should be_false
18
+ end
19
+
20
+ it "provides a failure message for #should" do
21
+ matcher = HaveConstantMatcher.new :A
22
+ matcher.matches?(HCMSpecs)
23
+ matcher.failure_message.should == [
24
+ "Expected HCMSpecs to have constant 'A'",
25
+ "but it does not"
26
+ ]
27
+ end
28
+
29
+ it "provides a failure messoge for #should_not" do
30
+ matcher = HaveConstantMatcher.new :X
31
+ matcher.matches?(HCMSpecs)
32
+ matcher.negative_failure_message.should == [
33
+ "Expected HCMSpecs NOT to have constant 'X'",
34
+ "but it does"
35
+ ]
36
+ end
37
+ end
@@ -0,0 +1,40 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'mspec/expectations/expectations'
3
+ require 'mspec/matchers/stringsymboladapter'
4
+
5
+ class StringSymbolSpecs
6
+ include StringSymbolAdapter
7
+ end
8
+
9
+ describe StringSymbolAdapter, "#convert_name" do
10
+ before :all do
11
+ @verbose = $VERBOSE
12
+ $VERBOSE = nil
13
+ end
14
+
15
+ after :all do
16
+ $VERBOSE = @verbose
17
+ end
18
+
19
+ before :each do
20
+ @ruby_version = Object.const_get :RUBY_VERSION
21
+
22
+ @name = mock("name")
23
+ end
24
+
25
+ after :each do
26
+ Object.const_set :RUBY_VERSION, @ruby_version
27
+ end
28
+
29
+ it "converts the name to a string if RUBY_VERSION < 1.9" do
30
+ Object.const_set :RUBY_VERSION, "1.8.6"
31
+ @name.should_receive(:to_s).and_return("method_name")
32
+ StringSymbolSpecs.new.convert_name @name
33
+ end
34
+
35
+ it "does not convert the name to a string if RUBY_VERSION >= 1.9" do
36
+ Object.const_set :RUBY_VERSION, "1.9.0"
37
+ @name.should_not_receive(:to_s)
38
+ StringSymbolSpecs.new.convert_name @name
39
+ end
40
+ end
@@ -81,6 +81,7 @@ describe TagPurgeAction, "#unload" do
81
81
 
82
82
  it "does not rewrite any tags if there were no tags for the specs" do
83
83
  MSpec.should_receive(:read_tags).and_return([])
84
+ MSpec.should_receive(:delete_tags)
84
85
  MSpec.should_not_receive(:write_tags)
85
86
 
86
87
  @action.load
@@ -69,6 +69,19 @@ describe Tally, "#errors!" do
69
69
  end
70
70
  end
71
71
 
72
+ describe Tally, "#guards!" do
73
+ before :each do
74
+ @tally = Tally.new
75
+ end
76
+
77
+ it "increments the count returned by #guards" do
78
+ @tally.guards!
79
+ @tally.guards.should == 1
80
+ @tally.guards! 2
81
+ @tally.guards.should == 3
82
+ end
83
+ end
84
+
72
85
  describe Tally, "#file" do
73
86
  before :each do
74
87
  @tally = Tally.new
@@ -139,11 +152,29 @@ describe Tally, "#error" do
139
152
  end
140
153
  end
141
154
 
155
+ describe Tally, "#guard" do
156
+ before :each do
157
+ @tally = Tally.new
158
+ end
159
+
160
+ it "returns a formatted string of the number of #guards" do
161
+ @tally.guard.should == "0 guards"
162
+ @tally.guards!
163
+ @tally.guard.should == "1 guard"
164
+ @tally.guards!
165
+ @tally.guard.should == "2 guards"
166
+ end
167
+ end
168
+
142
169
  describe Tally, "#format" do
143
170
  before :each do
144
171
  @tally = Tally.new
145
172
  end
146
173
 
174
+ after :each do
175
+ MSpec.clear_modes
176
+ end
177
+
147
178
  it "returns a formatted string of counts" do
148
179
  @tally.files!
149
180
  @tally.examples! 2
@@ -151,6 +182,39 @@ describe Tally, "#format" do
151
182
  @tally.errors!
152
183
  @tally.format.should == "1 file, 2 examples, 4 expectations, 0 failures, 1 error"
153
184
  end
185
+
186
+ it "includes guards if MSpec is in verify mode" do
187
+ MSpec.register_mode :verify
188
+ @tally.files!
189
+ @tally.examples! 2
190
+ @tally.expectations! 4
191
+ @tally.errors!
192
+ @tally.guards!
193
+ @tally.format.should ==
194
+ "1 file, 2 examples, 4 expectations, 0 failures, 1 error, 1 guard"
195
+ end
196
+
197
+ it "includes guards if MSpec is in report mode" do
198
+ MSpec.register_mode :report
199
+ @tally.files!
200
+ @tally.examples! 2
201
+ @tally.expectations! 4
202
+ @tally.errors!
203
+ @tally.guards! 2
204
+ @tally.format.should ==
205
+ "1 file, 2 examples, 4 expectations, 0 failures, 1 error, 2 guards"
206
+ end
207
+
208
+ it "includes guards if MSpec is in report_on mode" do
209
+ MSpec.register_mode :report_on
210
+ @tally.files!
211
+ @tally.examples! 2
212
+ @tally.expectations! 4
213
+ @tally.errors!
214
+ @tally.guards! 2
215
+ @tally.format.should ==
216
+ "1 file, 2 examples, 4 expectations, 0 failures, 1 error, 2 guards"
217
+ end
154
218
  end
155
219
 
156
220
  describe TallyAction, "#counter" do
@@ -91,14 +91,27 @@ describe ContextState, "#it" do
91
91
  before :each do
92
92
  @state = ContextState.new ""
93
93
  @proc = lambda { }
94
+
95
+ @ex = ExampleState.new("", "", &@proc)
94
96
  end
95
97
 
96
98
  it "creates an ExampleState instance for the block" do
97
- ex = ExampleState.new("", "", &@proc)
98
- ExampleState.should_receive(:new).with(@state, "it", @proc).and_return(ex)
99
+ ExampleState.should_receive(:new).with(@state, "it", @proc).and_return(@ex)
99
100
  @state.describe(&@proc)
100
101
  @state.it("it", &@proc)
101
102
  end
103
+
104
+ it "calls registered :add actions" do
105
+ ExampleState.should_receive(:new).with(@state, "it", @proc).and_return(@ex)
106
+
107
+ add_action = mock("add")
108
+ add_action.should_receive(:add).with(@ex).and_return { ScratchPad.record :add }
109
+ MSpec.register :add, add_action
110
+
111
+ @state.it("it", &@proc)
112
+ ScratchPad.recorded.should == :add
113
+ MSpec.unregister :add, add_action
114
+ end
102
115
  end
103
116
 
104
117
  describe ContextState, "#examples" do
@@ -544,7 +557,7 @@ describe ContextState, "#process" do
544
557
  MSpec.store :example, nil
545
558
  end
546
559
 
547
- it "calls registered example actions with the current ExampleState and block" do
560
+ it "calls registered :example actions with the current ExampleState and block" do
548
561
  @state.it("") { MSpec.expectation }
549
562
  @state.process
550
563
 
@@ -574,7 +587,7 @@ describe ContextState, "#process" do
574
587
  MSpec.store :after, nil
575
588
  end
576
589
 
577
- it "calls registered before actions with the current ExampleState instance" do
590
+ it "calls registered :before actions with the current ExampleState instance" do
578
591
  before = mock("before")
579
592
  before.should_receive(:before).and_return {
580
593
  ScratchPad.record :before
@@ -586,7 +599,7 @@ describe ContextState, "#process" do
586
599
  @spec_state.should be_kind_of(ExampleState)
587
600
  end
588
601
 
589
- it "calls registered after actions with the current ExampleState instance" do
602
+ it "calls registered :after actions with the current ExampleState instance" do
590
603
  after = mock("after")
591
604
  after.should_receive(:after).and_return {
592
605
  ScratchPad.record :after
@@ -614,7 +627,7 @@ describe ContextState, "#process" do
614
627
  MSpec.store :leave, nil
615
628
  end
616
629
 
617
- it "calls registered enter actions with the current #describe string" do
630
+ it "calls registered :enter actions with the current #describe string" do
618
631
  enter = mock("enter")
619
632
  enter.should_receive(:enter).with("C#m").and_return { ScratchPad.record :enter }
620
633
  MSpec.register :enter, enter
@@ -622,7 +635,7 @@ describe ContextState, "#process" do
622
635
  ScratchPad.recorded.should == :enter
623
636
  end
624
637
 
625
- it "calls registered leave actions" do
638
+ it "calls registered :leave actions" do
626
639
  leave = mock("leave")
627
640
  leave.should_receive(:leave).and_return { ScratchPad.record :leave }
628
641
  MSpec.register :leave, leave
@@ -755,7 +768,7 @@ describe ContextState, "#process in pretend mode" do
755
768
  MSpec.store :after, nil
756
769
  end
757
770
 
758
- it "calls registered before actions with the current ExampleState instance" do
771
+ it "calls registered :before actions with the current ExampleState instance" do
759
772
  before = mock("before")
760
773
  before.should_receive(:before).and_return {
761
774
  ScratchPad.record :before
@@ -767,7 +780,7 @@ describe ContextState, "#process in pretend mode" do
767
780
  @spec_state.should be_kind_of(ExampleState)
768
781
  end
769
782
 
770
- it "calls registered after actions with the current ExampleState instance" do
783
+ it "calls registered :after actions with the current ExampleState instance" do
771
784
  after = mock("after")
772
785
  after.should_receive(:after).and_return {
773
786
  ScratchPad.record :after
@@ -878,7 +891,7 @@ describe ContextState, "#process in pretend mode" do
878
891
  MSpec.store :leave, nil
879
892
  end
880
893
 
881
- it "calls registered enter actions with the current #describe string" do
894
+ it "calls registered :enter actions with the current #describe string" do
882
895
  enter = mock("enter")
883
896
  enter.should_receive(:enter).and_return { ScratchPad.record :enter }
884
897
  MSpec.register :enter, enter
@@ -886,7 +899,7 @@ describe ContextState, "#process in pretend mode" do
886
899
  ScratchPad.recorded.should == :enter
887
900
  end
888
901
 
889
- it "calls registered leave actions" do
902
+ it "calls registered :leave actions" do
890
903
  leave = mock("leave")
891
904
  leave.should_receive(:leave).and_return { ScratchPad.record :leave }
892
905
  MSpec.register :leave, leave