must_be 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ChangeLog.md +6 -1
- data/Rakefile +6 -3
- data/VERSION +1 -1
- data/lib/must_be/attr_typed.rb +2 -2
- data/lib/must_be/containers.rb +5 -5
- data/must_be.gemspec +8 -2
- data/spec/must_be/containers_spec.rb +3 -7
- data/spec/must_be/core_spec.rb +1 -0
- data/spec/must_be/nonstandard_control_flow_spec.rb +8 -8
- data/spec/must_be/proxy_spec.rb +2 -2
- data/spec/notify_matcher_spec.rb +10 -1
- data/spec/spec_helper.rb +48 -28
- metadata +35 -6
data/ChangeLog.md
CHANGED
data/Rakefile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'rspec/core/rake_task'
|
2
2
|
|
3
3
|
begin
|
4
4
|
require 'jeweler'
|
@@ -9,6 +9,9 @@ begin
|
|
9
9
|
gemspec.email = "wtaysom@gmail.com"
|
10
10
|
gemspec.homepage = "http://github.com/wtaysom/must_be"
|
11
11
|
gemspec.authors = ["William Taysom"]
|
12
|
+
|
13
|
+
gemspec.add_development_dependency('jeweler', '~> 1.4')
|
14
|
+
gemspec.add_development_dependency('rspec', '~> 2.0')
|
12
15
|
end
|
13
16
|
Jeweler::GemcutterTasks.new
|
14
17
|
rescue LoadError
|
@@ -16,9 +19,9 @@ rescue LoadError
|
|
16
19
|
end
|
17
20
|
|
18
21
|
desc "Run the spec suite against rcov"
|
19
|
-
|
22
|
+
RSpec::Core::RakeTask.new(:rcov_helper) do |t|
|
20
23
|
t.rcov = true
|
21
|
-
t.rcov_opts =
|
24
|
+
t.rcov_opts = %q{--exclude "gems/,spec/"}
|
22
25
|
end
|
23
26
|
|
24
27
|
desc "Run the spec suite against rcov and open coverage results"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.3
|
data/lib/must_be/attr_typed.rb
CHANGED
@@ -54,12 +54,12 @@ class Module
|
|
54
54
|
end
|
55
55
|
))
|
56
56
|
|
57
|
-
module_eval
|
57
|
+
module_eval(<<-END, __FILE__, __LINE__ + 1)
|
58
58
|
def #{name}=(value)
|
59
59
|
#{check_method_name}(value)
|
60
60
|
@#{name} = value
|
61
61
|
end
|
62
|
-
|
62
|
+
END
|
63
63
|
end
|
64
64
|
|
65
65
|
MustBe.register_disabled_handler do |enabled|
|
data/lib/must_be/containers.rb
CHANGED
@@ -152,7 +152,7 @@ module MustBe
|
|
152
152
|
module ClassMethods
|
153
153
|
def must_check_contents_after(*methods)
|
154
154
|
methods.each do |method|
|
155
|
-
module_eval
|
155
|
+
module_eval(<<-END, __FILE__, __LINE__ + 1)
|
156
156
|
def #{method}(*args)
|
157
157
|
begin
|
158
158
|
super
|
@@ -160,7 +160,7 @@ module MustBe
|
|
160
160
|
must_check_contents
|
161
161
|
end
|
162
162
|
end
|
163
|
-
|
163
|
+
END
|
164
164
|
end
|
165
165
|
end
|
166
166
|
end
|
@@ -229,11 +229,11 @@ module MustBe
|
|
229
229
|
|
230
230
|
REGISTERED_CLASSES[klass] = mod = Module.new
|
231
231
|
mod.send(:include, Base)
|
232
|
-
mod.class_eval
|
232
|
+
mod.class_eval(&body)
|
233
233
|
|
234
234
|
mutator_advice = Module.new
|
235
235
|
mod.instance_methods(false).each do |method_name|
|
236
|
-
mutator_advice.module_eval
|
236
|
+
mutator_advice.module_eval(<<-END, __FILE__, __LINE__ + 1)
|
237
237
|
def #{method_name}(*args, &block)
|
238
238
|
must_check(lambda { super(*args, &block) }) do |note|
|
239
239
|
note.prefix = nil
|
@@ -244,7 +244,7 @@ module MustBe
|
|
244
244
|
note
|
245
245
|
end
|
246
246
|
end
|
247
|
-
|
247
|
+
END
|
248
248
|
end
|
249
249
|
mod.const_set(:MutatorAdvice, mutator_advice)
|
250
250
|
mod.instance_eval do
|
data/must_be.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{must_be}
|
8
|
-
s.version = "1.0.
|
8
|
+
s.version = "1.0.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["William Taysom"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-11-01}
|
13
13
|
s.description = %q{must_be provides runtime assertions which can easily be disabled in production environments. Likewise, the notifier can be customized to raise errors, log failure, enter the debugger, or anything else.}
|
14
14
|
s.email = %q{wtaysom@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -65,9 +65,15 @@ Gem::Specification.new do |s|
|
|
65
65
|
s.specification_version = 3
|
66
66
|
|
67
67
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
68
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.4"])
|
69
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.0"])
|
68
70
|
else
|
71
|
+
s.add_dependency(%q<jeweler>, ["~> 1.4"])
|
72
|
+
s.add_dependency(%q<rspec>, ["~> 2.0"])
|
69
73
|
end
|
70
74
|
else
|
75
|
+
s.add_dependency(%q<jeweler>, ["~> 1.4"])
|
76
|
+
s.add_dependency(%q<rspec>, ["~> 2.0"])
|
71
77
|
end
|
72
78
|
end
|
73
79
|
|
@@ -719,10 +719,8 @@ describe MustBe do
|
|
719
719
|
end
|
720
720
|
end
|
721
721
|
end
|
722
|
-
|
723
|
-
|
724
|
-
it_should_behave_like "custom MustOnlyEverContain"
|
725
|
-
|
722
|
+
|
723
|
+
it_should_behave_like "custom MustOnlyEverContain" do
|
726
724
|
context "without MustOnlyEverContain.registered_class" do
|
727
725
|
describe '#must_only_contain' do
|
728
726
|
it "should use each to check the contents" do
|
@@ -881,9 +879,7 @@ describe MustBe do
|
|
881
879
|
end
|
882
880
|
end
|
883
881
|
|
884
|
-
|
885
|
-
it_should_behave_like "custom MustOnlyEverContain"
|
886
|
-
|
882
|
+
it_should_behave_like "custom MustOnlyEverContain" do
|
887
883
|
describe "without MustOnlyEverContain.registered_class" do
|
888
884
|
describe '#must_not_contain' do
|
889
885
|
it "should use each to check the contents" do
|
data/spec/must_be/core_spec.rb
CHANGED
@@ -634,13 +634,13 @@ describe MustBe do
|
|
634
634
|
throw :ball, :gently
|
635
635
|
end
|
636
636
|
ensure
|
637
|
-
note =
|
638
|
-
|
637
|
+
note = $note
|
638
|
+
$note = nil
|
639
639
|
end
|
640
640
|
end
|
641
641
|
ensure
|
642
|
-
outer_note =
|
643
|
-
|
642
|
+
outer_note = $note
|
643
|
+
$note = nil
|
644
644
|
end
|
645
645
|
end
|
646
646
|
end.should throw_symbol(:ball)
|
@@ -825,13 +825,13 @@ describe MustBe do
|
|
825
825
|
throw :ball, :gently
|
826
826
|
end
|
827
827
|
ensure
|
828
|
-
note =
|
829
|
-
|
828
|
+
note = $note
|
829
|
+
$note = nil
|
830
830
|
end
|
831
831
|
end
|
832
832
|
ensure
|
833
|
-
outer_note =
|
834
|
-
|
833
|
+
outer_note = $note
|
834
|
+
$note = nil
|
835
835
|
end
|
836
836
|
end
|
837
837
|
end.should throw_symbol(:ball)
|
data/spec/must_be/proxy_spec.rb
CHANGED
@@ -29,14 +29,14 @@ describe MustBe do
|
|
29
29
|
module ItShouldNotifyExpectations
|
30
30
|
def it_should_notify(message, &implementation)
|
31
31
|
example "#{message} should notify" do
|
32
|
-
instance_eval
|
32
|
+
instance_eval(&implementation)
|
33
33
|
should notify(message)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
37
|
def it_should_not_notify(message, &implementation)
|
38
38
|
example "#{message} should not notify" do
|
39
|
-
instance_eval
|
39
|
+
instance_eval(&implementation)
|
40
40
|
should_not notify
|
41
41
|
end
|
42
42
|
end
|
data/spec/notify_matcher_spec.rb
CHANGED
@@ -29,10 +29,19 @@ describe "Notify Matcher" do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
pattern_notify.send(result ? :should : :should_not, raise_error(
|
32
|
-
|
32
|
+
RSpec::Expectations::ExpectationNotMetError, result))
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
36
|
+
|
37
|
+
context "when called with more than one argument" do
|
38
|
+
it "should raise ArgumentError" do
|
39
|
+
expect do
|
40
|
+
:it.should notify("one", "two")
|
41
|
+
end.should raise_error(ArgumentError,
|
42
|
+
"wrong number of arguments (2 for 1)")
|
43
|
+
end
|
44
|
+
end
|
36
45
|
|
37
46
|
it_should_follow_pattern :note, :should, nil, nil
|
38
47
|
it_should_follow_pattern :note, :should, 'same', nil
|
data/spec/spec_helper.rb
CHANGED
@@ -55,6 +55,8 @@ end
|
|
55
55
|
|
56
56
|
### MustBeExampleHelper ###
|
57
57
|
|
58
|
+
require 'rspec'
|
59
|
+
|
58
60
|
module MustBeExampleHelper
|
59
61
|
|
60
62
|
$default_must_be_notifier = MustBe.notifier
|
@@ -62,10 +64,14 @@ module MustBeExampleHelper
|
|
62
64
|
def self.included(example_group)
|
63
65
|
example_group.before do
|
64
66
|
MustBe.notifier = lambda do |note|
|
65
|
-
|
67
|
+
$note = note
|
66
68
|
false
|
67
69
|
end
|
68
70
|
end
|
71
|
+
|
72
|
+
example_group.after do
|
73
|
+
$note = nil
|
74
|
+
end
|
69
75
|
|
70
76
|
class <<example_group
|
71
77
|
|
@@ -141,40 +147,54 @@ module MustBeExampleHelper
|
|
141
147
|
|
142
148
|
### Notify Matcher ###
|
143
149
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
150
|
+
RSpec::Matchers.define :notify do |*message|
|
151
|
+
if (count = message.size) > 1
|
152
|
+
raise ArgumentError, "wrong number of arguments (#{count} for 1)"
|
153
|
+
end
|
154
|
+
message = message[0]
|
155
|
+
|
156
|
+
def does(message)
|
157
|
+
@message = message
|
158
|
+
true
|
159
|
+
end
|
160
|
+
|
161
|
+
def does_not(message)
|
162
|
+
@message = message
|
163
|
+
false
|
164
|
+
end
|
165
|
+
|
166
|
+
match do |given|
|
167
|
+
if $note
|
168
|
+
if message
|
169
|
+
if message === $note.message
|
170
|
+
does(
|
171
|
+
"did NOT expect note with message: #{message.inspect}\n"\
|
172
|
+
" got note with message: #{$note.message.inspect}")
|
158
173
|
else
|
159
|
-
|
160
|
-
"expected
|
161
|
-
"got note with message: #{
|
174
|
+
does_not(
|
175
|
+
"expected note with message: #{message.inspect}\n"\
|
176
|
+
" got note with message: #{$note.message.inspect}")
|
162
177
|
end
|
163
178
|
else
|
164
|
-
|
165
|
-
"expected
|
166
|
-
|
167
|
-
"expected a note"
|
168
|
-
end]
|
179
|
+
does(
|
180
|
+
"expected no note\n"\
|
181
|
+
"got note with message: #{$note.message.inspect}")
|
169
182
|
end
|
170
|
-
|
171
|
-
if result
|
172
|
-
matcher.negative_failure_message = message
|
173
183
|
else
|
174
|
-
|
184
|
+
does_not(if message
|
185
|
+
"expected a note with message: #{message.inspect}"
|
186
|
+
else
|
187
|
+
"expected a note"
|
188
|
+
end)
|
175
189
|
end
|
190
|
+
end
|
191
|
+
|
192
|
+
failure_message_for_should do |given|
|
193
|
+
@message
|
194
|
+
end
|
176
195
|
|
177
|
-
|
196
|
+
failure_message_for_should_not do |given|
|
197
|
+
@message
|
178
198
|
end
|
179
199
|
end
|
180
200
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: must_be
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 3
|
10
|
+
version: 1.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- William Taysom
|
@@ -15,10 +15,39 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-11-01 00:00:00 +08:00
|
19
19
|
default_executable:
|
20
|
-
dependencies:
|
21
|
-
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: jeweler
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 7
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 4
|
33
|
+
version: "1.4"
|
34
|
+
type: :development
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 3
|
45
|
+
segments:
|
46
|
+
- 2
|
47
|
+
- 0
|
48
|
+
version: "2.0"
|
49
|
+
type: :development
|
50
|
+
version_requirements: *id002
|
22
51
|
description: must_be provides runtime assertions which can easily be disabled in production environments. Likewise, the notifier can be customized to raise errors, log failure, enter the debugger, or anything else.
|
23
52
|
email: wtaysom@gmail.com
|
24
53
|
executables: []
|