mspec 1.5.11 → 1.5.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/Rakefile +1 -1
  2. data/lib/mspec/commands/mspec-ci.rb +1 -0
  3. data/lib/mspec/commands/mspec-run.rb +1 -0
  4. data/lib/mspec/commands/mspec-tag.rb +1 -0
  5. data/lib/mspec/helpers.rb +4 -0
  6. data/lib/mspec/helpers/ducktype.rb +33 -0
  7. data/lib/mspec/helpers/enumerator_class.rb +9 -0
  8. data/lib/mspec/helpers/environment.rb +10 -1
  9. data/lib/mspec/helpers/hash.rb +27 -0
  10. data/lib/mspec/helpers/io.rb +4 -0
  11. data/lib/mspec/helpers/metaclass.rb +7 -0
  12. data/lib/mspec/matchers.rb +5 -0
  13. data/lib/mspec/matchers/have_class_variable.rb +12 -0
  14. data/lib/mspec/matchers/have_constant.rb +6 -24
  15. data/lib/mspec/matchers/have_instance_variable.rb +12 -0
  16. data/lib/mspec/matchers/have_protected_instance_method.rb +24 -0
  17. data/lib/mspec/matchers/have_public_instance_method.rb +24 -0
  18. data/lib/mspec/matchers/stringsymboladapter.rb +1 -1
  19. data/lib/mspec/matchers/variable.rb +28 -0
  20. data/lib/mspec/mocks/mock.rb +70 -47
  21. data/lib/mspec/mocks/object.rb +4 -0
  22. data/lib/mspec/mocks/proxy.rb +17 -3
  23. data/lib/mspec/runner.rb +1 -0
  24. data/lib/mspec/runner/exception.rb +4 -3
  25. data/lib/mspec/utils/options.rb +10 -2
  26. data/lib/mspec/version.rb +1 -1
  27. data/spec/commands/mkspec_spec.rb +1 -1
  28. data/spec/commands/mspec_ci_spec.rb +5 -0
  29. data/spec/commands/mspec_run_spec.rb +5 -0
  30. data/spec/commands/mspec_spec.rb +2 -2
  31. data/spec/commands/mspec_tag_spec.rb +5 -0
  32. data/spec/expectations/should.rb +1 -0
  33. data/spec/helpers/ducktype_spec.rb +44 -0
  34. data/spec/helpers/enumerator_class_spec.rb +19 -0
  35. data/spec/helpers/hash_spec.rb +30 -0
  36. data/spec/helpers/io_spec.rb +5 -0
  37. data/spec/matchers/have_class_variable_spec.rb +75 -0
  38. data/spec/matchers/have_instance_variable_spec.rb +75 -0
  39. data/spec/matchers/have_protected_instance_method_spec.rb +57 -0
  40. data/spec/matchers/have_public_instance_method_spec.rb +53 -0
  41. data/spec/matchers/stringsymboladapter_spec.rb +8 -10
  42. data/spec/mocks/mock_spec.rb +5 -5
  43. data/spec/runner/exception_spec.rb +17 -10
  44. data/spec/utils/options_spec.rb +26 -0
  45. metadata +18 -2
@@ -0,0 +1,57 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'mspec/expectations/expectations'
3
+ require 'mspec/matchers/have_protected_instance_method'
4
+
5
+ class HPIMMSpecs
6
+ protected
7
+
8
+ def protected_method
9
+ end
10
+
11
+ class Subclass < HPIMMSpecs
12
+ protected
13
+
14
+ def protected_sub_method
15
+ end
16
+ end
17
+ end
18
+
19
+ describe HaveProtectedInstanceMethodMatcher do
20
+ it "inherits from MethodMatcher" do
21
+ HaveProtectedInstanceMethodMatcher.new(:m).should be_kind_of(MethodMatcher)
22
+ end
23
+
24
+ it "matches when mod has the protected instance method" do
25
+ matcher = HaveProtectedInstanceMethodMatcher.new :protected_method
26
+ matcher.matches?(HPIMMSpecs).should be_true
27
+ matcher.matches?(HPIMMSpecs::Subclass).should be_true
28
+ end
29
+
30
+ it "does not match when mod does not have the protected instance method" do
31
+ matcher = HaveProtectedInstanceMethodMatcher.new :another_method
32
+ matcher.matches?(HPIMMSpecs).should be_false
33
+ end
34
+
35
+ it "does not match if the method is in a superclass and include_super is false" do
36
+ matcher = HaveProtectedInstanceMethodMatcher.new :protected_method, false
37
+ matcher.matches?(HPIMMSpecs::Subclass).should be_false
38
+ end
39
+
40
+ it "provides a failure message for #should" do
41
+ matcher = HaveProtectedInstanceMethodMatcher.new :some_method
42
+ matcher.matches?(HPIMMSpecs)
43
+ matcher.failure_message.should == [
44
+ "Expected HPIMMSpecs to have protected instance method 'some_method'",
45
+ "but it does not"
46
+ ]
47
+ end
48
+
49
+ it "provides a failure messoge for #should_not" do
50
+ matcher = HaveProtectedInstanceMethodMatcher.new :some_method
51
+ matcher.matches?(HPIMMSpecs)
52
+ matcher.negative_failure_message.should == [
53
+ "Expected HPIMMSpecs NOT to have protected instance method 'some_method'",
54
+ "but it does"
55
+ ]
56
+ end
57
+ end
@@ -0,0 +1,53 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'mspec/expectations/expectations'
3
+ require 'mspec/matchers/have_public_instance_method'
4
+
5
+ class HPIMMSpecs
6
+ def public_method
7
+ end
8
+
9
+ class Subclass < HPIMMSpecs
10
+ def public_sub_method
11
+ end
12
+ end
13
+ end
14
+
15
+ describe HavePublicInstanceMethodMatcher do
16
+ it "inherits from MethodMatcher" do
17
+ HavePublicInstanceMethodMatcher.new(:m).should be_kind_of(MethodMatcher)
18
+ end
19
+
20
+ it "matches when mod has the public instance method" do
21
+ matcher = HavePublicInstanceMethodMatcher.new :public_method
22
+ matcher.matches?(HPIMMSpecs).should be_true
23
+ matcher.matches?(HPIMMSpecs::Subclass).should be_true
24
+ end
25
+
26
+ it "does not match when mod does not have the public instance method" do
27
+ matcher = HavePublicInstanceMethodMatcher.new :another_method
28
+ matcher.matches?(HPIMMSpecs).should be_false
29
+ end
30
+
31
+ it "does not match if the method is in a superclass and include_super is false" do
32
+ matcher = HavePublicInstanceMethodMatcher.new :public_method, false
33
+ matcher.matches?(HPIMMSpecs::Subclass).should be_false
34
+ end
35
+
36
+ it "provides a failure message for #should" do
37
+ matcher = HavePublicInstanceMethodMatcher.new :some_method
38
+ matcher.matches?(HPIMMSpecs)
39
+ matcher.failure_message.should == [
40
+ "Expected HPIMMSpecs to have public instance method 'some_method'",
41
+ "but it does not"
42
+ ]
43
+ end
44
+
45
+ it "provides a failure messoge for #should_not" do
46
+ matcher = HavePublicInstanceMethodMatcher.new :some_method
47
+ matcher.matches?(HPIMMSpecs)
48
+ matcher.negative_failure_message.should == [
49
+ "Expected HPIMMSpecs NOT to have public instance method 'some_method'",
50
+ "but it does"
51
+ ]
52
+ end
53
+ end
@@ -2,11 +2,9 @@ require File.dirname(__FILE__) + '/../spec_helper'
2
2
  require 'mspec/expectations/expectations'
3
3
  require 'mspec/matchers/stringsymboladapter'
4
4
 
5
- class StringSymbolSpecs
5
+ describe StringSymbolAdapter, "#convert_name" do
6
6
  include StringSymbolAdapter
7
- end
8
7
 
9
- describe StringSymbolAdapter, "#convert_name" do
10
8
  before :all do
11
9
  @verbose = $VERBOSE
12
10
  $VERBOSE = nil
@@ -18,8 +16,6 @@ describe StringSymbolAdapter, "#convert_name" do
18
16
 
19
17
  before :each do
20
18
  @ruby_version = Object.const_get :RUBY_VERSION
21
-
22
- @name = mock("name")
23
19
  end
24
20
 
25
21
  after :each do
@@ -28,13 +24,15 @@ describe StringSymbolAdapter, "#convert_name" do
28
24
 
29
25
  it "converts the name to a string if RUBY_VERSION < 1.9" do
30
26
  Object.const_set :RUBY_VERSION, "1.8.6"
31
- @name.should_receive(:to_s).and_return("method_name")
32
- StringSymbolSpecs.new.convert_name @name
27
+
28
+ convert_name("name").should == "name"
29
+ convert_name(:name).should == "name"
33
30
  end
34
31
 
35
- it "does not convert the name to a string if RUBY_VERSION >= 1.9" do
32
+ it "converts the name to a symbol if RUBY_VERSION >= 1.9" do
36
33
  Object.const_set :RUBY_VERSION, "1.9.0"
37
- @name.should_not_receive(:to_s)
38
- StringSymbolSpecs.new.convert_name @name
34
+
35
+ convert_name("name").should == :name
36
+ convert_name(:name).should == :name
39
37
  end
40
38
  end
@@ -23,7 +23,7 @@ describe Mock, ".replaced_name" do
23
23
  it "returns the name for a method that is being replaced by a mock method" do
24
24
  m = mock('a fake id')
25
25
  m.stub!(:__id__).and_return(42)
26
- Mock.replaced_name(m, :method_call).should == :__ms_42_method_call__
26
+ Mock.replaced_name(m, :method_call).should == :__mspec_42_method_call__
27
27
  end
28
28
  end
29
29
 
@@ -31,7 +31,7 @@ describe Mock, ".replaced_key" do
31
31
  it "returns a key used internally by Mock" do
32
32
  m = mock('a fake id')
33
33
  m.stub!(:__id__).and_return(42)
34
- Mock.replaced_key(m, :method_call).should == [:__ms_42_method_call__, m, :method_call]
34
+ Mock.replaced_key(m, :method_call).should == [:__mspec_42_method_call__, :method_call]
35
35
  end
36
36
  end
37
37
 
@@ -44,16 +44,16 @@ describe Mock, ".replaced?" do
44
44
 
45
45
  it "returns true if a method has been stubbed on an object" do
46
46
  Mock.install_method @mock, :method_call
47
- Mock.replaced?(Mock.replaced_key(@mock, :method_call)).should be_true
47
+ Mock.replaced?(Mock.replaced_name(@mock, :method_call)).should be_true
48
48
  end
49
49
 
50
50
  it "returns true if a method has been mocked on an object" do
51
51
  Mock.install_method @mock, :method_call, :stub
52
- Mock.replaced?(Mock.replaced_key(@mock, :method_call)).should be_true
52
+ Mock.replaced?(Mock.replaced_name(@mock, :method_call)).should be_true
53
53
  end
54
54
 
55
55
  it "returns false if a method has not been stubbed or mocked" do
56
- Mock.replaced?(Mock.replaced_key(@mock, :method_call)).should be_false
56
+ Mock.replaced?(Mock.replaced_name(@mock, :method_call)).should be_false
57
57
  end
58
58
  end
59
59
 
@@ -2,6 +2,7 @@ require File.dirname(__FILE__) + '/../spec_helper'
2
2
  require 'mspec/expectations/expectations'
3
3
  require 'mspec/runner/example'
4
4
  require 'mspec/runner/exception'
5
+ require 'mspec/utils/script'
5
6
 
6
7
  describe ExceptionState, "#initialize" do
7
8
  it "takes a state, location (e.g. before :each), and exception" do
@@ -110,25 +111,31 @@ end
110
111
 
111
112
  describe ExceptionState, "#backtrace" do
112
113
  before :each do
113
- @action = mock("action")
114
- def @action.exception(exc)
115
- ScratchPad.record exc.exception
114
+ begin
115
+ raise Exception
116
+ rescue Exception => @exception
117
+ @exc = ExceptionState.new @state, "", @exception
116
118
  end
117
- MSpec.register :exception, @action
118
-
119
- ScratchPad.clear
120
- MSpec.protect("") { raise Exception }
119
+ end
121
120
 
122
- @exc = ExceptionState.new @state, "", ScratchPad.recorded
121
+ after :each do
122
+ $MSPEC_DEBUG = nil
123
123
  end
124
124
 
125
125
  it "returns a string representation of the exception backtrace" do
126
126
  @exc.backtrace.should be_kind_of(String)
127
127
  end
128
128
 
129
- it "strips MSpec files from the backtrace" do
129
+ it "does not filter files from the backtrace if $MSPEC_DEBUG is true" do
130
+ $MSPEC_DEBUG = true
131
+ @exc.backtrace.should == @exception.backtrace.join("\n")
132
+ end
133
+
134
+ it "filters files matching config[:backtrace_filter]" do
135
+ MSpecScript.set :backtrace_filter, %r[mspec/lib]
136
+ $MSPEC_DEBUG = nil
130
137
  @exc.backtrace.split("\n").each do |line|
131
- line.should_not =~ ExceptionState::PATH
138
+ line.should_not =~ %r[mspec/lib]
132
139
  end
133
140
  end
134
141
  end
@@ -1290,3 +1290,29 @@ describe "The --spec-gdb option" do
1290
1290
  @config[:gdb].should == true
1291
1291
  end
1292
1292
  end
1293
+
1294
+ describe "The -d, --debug option" do
1295
+ before :each do
1296
+ @options, @config = new_option
1297
+ @options.debug
1298
+ end
1299
+
1300
+ after :each do
1301
+ $MSPEC_DEBUG = nil
1302
+ end
1303
+
1304
+ it "is enabled with #debug" do
1305
+ @options.stub!(:on)
1306
+ @options.should_receive(:on).with("-d", "--debug", an_instance_of(String))
1307
+ @options.debug
1308
+ end
1309
+
1310
+ it "sets $MSPEC_DEBUG to true" do
1311
+ ["-d", "--debug"].each do |opt|
1312
+ $MSPEC_DEBUG.should_not be_true
1313
+ @options.parse opt
1314
+ $MSPEC_DEBUG.should be_true
1315
+ $MSPEC_DEBUG = nil
1316
+ end
1317
+ end
1318
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.11
4
+ version: 1.5.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Ford
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-30 00:00:00 -07:00
12
+ date: 2009-06-08 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -54,11 +54,15 @@ files:
54
54
  - lib/mspec/helpers/argv.rb
55
55
  - lib/mspec/helpers/bignum.rb
56
56
  - lib/mspec/helpers/const_lookup.rb
57
+ - lib/mspec/helpers/ducktype.rb
58
+ - lib/mspec/helpers/enumerator_class.rb
57
59
  - lib/mspec/helpers/environment.rb
58
60
  - lib/mspec/helpers/fixture.rb
59
61
  - lib/mspec/helpers/flunk.rb
62
+ - lib/mspec/helpers/hash.rb
60
63
  - lib/mspec/helpers/io.rb
61
64
  - lib/mspec/helpers/language_version.rb
65
+ - lib/mspec/helpers/metaclass.rb
62
66
  - lib/mspec/helpers/ruby_exe.rb
63
67
  - lib/mspec/helpers/scratch.rb
64
68
  - lib/mspec/helpers/tmp.rb
@@ -77,10 +81,14 @@ files:
77
81
  - lib/mspec/matchers/equal.rb
78
82
  - lib/mspec/matchers/equal_element.rb
79
83
  - lib/mspec/matchers/equal_utf16.rb
84
+ - lib/mspec/matchers/have_class_variable.rb
80
85
  - lib/mspec/matchers/have_constant.rb
81
86
  - lib/mspec/matchers/have_instance_method.rb
87
+ - lib/mspec/matchers/have_instance_variable.rb
82
88
  - lib/mspec/matchers/have_method.rb
83
89
  - lib/mspec/matchers/have_private_instance_method.rb
90
+ - lib/mspec/matchers/have_protected_instance_method.rb
91
+ - lib/mspec/matchers/have_public_instance_method.rb
84
92
  - lib/mspec/matchers/include.rb
85
93
  - lib/mspec/matchers/match_yaml.rb
86
94
  - lib/mspec/matchers/method.rb
@@ -89,6 +97,7 @@ files:
89
97
  - lib/mspec/matchers/raise_error.rb
90
98
  - lib/mspec/matchers/respond_to.rb
91
99
  - lib/mspec/matchers/stringsymboladapter.rb
100
+ - lib/mspec/matchers/variable.rb
92
101
  - lib/mspec/matchers.rb
93
102
  - lib/mspec/mocks/mock.rb
94
103
  - lib/mspec/mocks/object.rb
@@ -168,9 +177,12 @@ files:
168
177
  - spec/helpers/argv_spec.rb
169
178
  - spec/helpers/bignum_spec.rb
170
179
  - spec/helpers/const_lookup_spec.rb
180
+ - spec/helpers/ducktype_spec.rb
181
+ - spec/helpers/enumerator_class_spec.rb
171
182
  - spec/helpers/environment_spec.rb
172
183
  - spec/helpers/fixture_spec.rb
173
184
  - spec/helpers/flunk_spec.rb
185
+ - spec/helpers/hash_spec.rb
174
186
  - spec/helpers/io_spec.rb
175
187
  - spec/helpers/language_version_spec.rb
176
188
  - spec/helpers/ruby_exe_spec.rb
@@ -190,10 +202,14 @@ files:
190
202
  - spec/matchers/equal_element_spec.rb
191
203
  - spec/matchers/equal_spec.rb
192
204
  - spec/matchers/equal_utf16_spec.rb
205
+ - spec/matchers/have_class_variable_spec.rb
193
206
  - spec/matchers/have_constant_spec.rb
194
207
  - spec/matchers/have_instance_method_spec.rb
208
+ - spec/matchers/have_instance_variable_spec.rb
195
209
  - spec/matchers/have_method_spec.rb
196
210
  - spec/matchers/have_private_instance_method_spec.rb
211
+ - spec/matchers/have_protected_instance_method_spec.rb
212
+ - spec/matchers/have_public_instance_method_spec.rb
197
213
  - spec/matchers/include_spec.rb
198
214
  - spec/matchers/match_yaml_spec.rb
199
215
  - spec/matchers/output_spec.rb