MacSpec 0.3.3 → 0.4.0
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/MacSpec.gemspec +2 -2
- data/README.rdoc +4 -2
- data/lib/mac_spec/mocking_framework/extensions/object_extension.rb +0 -2
- data/lib/mac_spec/mocking_framework/message_expectation.rb +2 -1
- data/lib/mac_spec/testing_framework/core/kernel_extension.rb +1 -0
- data/lib/mac_spec/testing_framework/core/test_case_class_methods.rb +15 -7
- data/lib/mac_spec/version.rb +1 -1
- data/lib/macspec.rb +63 -2
- data/test/mac_spec/testing_framework/regression/inherit_not_double_test.rb +1 -1
- metadata +4 -4
data/MacSpec.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{MacSpec}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.4.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Matthias Hennemeyer"]
|
12
|
-
s.date = %q{2010-03-
|
12
|
+
s.date = %q{2010-03-07}
|
13
13
|
s.description = %q{MacSpec is a feature minimal RSpec clone that is specifically built to work with MacRuby.}
|
14
14
|
s.email = %q{mhennemeyer@me.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/README.rdoc
CHANGED
@@ -19,7 +19,8 @@ $sudo macgem install MacSpec
|
|
19
19
|
== Use
|
20
20
|
|
21
21
|
|
22
|
-
For Starters:
|
22
|
+
For Starters:
|
23
|
+
|
23
24
|
Create a brandnew MacRuby Application with the Xcode template that ships with MacRuby.
|
24
25
|
(Btw Have you installed MacRuby-0.5 already? http://www.macruby.org/downloads.html )
|
25
26
|
|
@@ -55,7 +56,8 @@ replace the content with:
|
|
55
56
|
end
|
56
57
|
end
|
57
58
|
end
|
58
|
-
|
59
|
+
|
60
|
+
Now set the active target to 'Unit Tests' and hit Cmd-B.
|
59
61
|
|
60
62
|
|
61
63
|
== Philosophy
|
@@ -12,8 +12,6 @@ module MacSpec
|
|
12
12
|
message_expectation = MacSpec::MockingFramework::MessageExpectation.new(options)
|
13
13
|
@__macspec__message_expectations << message_expectation
|
14
14
|
return message_expectation
|
15
|
-
# @__macspec__mock ||= MacSpec::MockingFramework::Mock.new(self.to_s, :belongs_to => self)
|
16
|
-
# __macspec__proxy_service(@__macspec__mock.__add_positive_message_expectation(msg))
|
17
15
|
end
|
18
16
|
|
19
17
|
def should_not_receive(msg)
|
@@ -31,7 +31,7 @@ module MacSpec
|
|
31
31
|
#
|
32
32
|
end
|
33
33
|
MessageExpectation.register_for_verification(@receiver)
|
34
|
-
@return_value = {}
|
34
|
+
@return_value = {:__macspec_anyargs => true}
|
35
35
|
@received = {}
|
36
36
|
@args_expectation = :__macspec_anyargs
|
37
37
|
end
|
@@ -59,6 +59,7 @@ module MacSpec
|
|
59
59
|
@return_value.each do |args,value|
|
60
60
|
args_string = (args == :__macspec_anyargs) ? "Any Args" : args.inspect
|
61
61
|
if (@received[args] && @positive) || (!@received[args] && !@positive)
|
62
|
+
|
62
63
|
MacSpec.assert(true)
|
63
64
|
elsif (!@received[args] && @positive)
|
64
65
|
received_with_args_string = if !@received.keys.include?(:__macspec_anyargs)
|
@@ -16,6 +16,7 @@ module Kernel
|
|
16
16
|
end
|
17
17
|
cls.teardown_chained = lambda {MacSpec::MockingFramework::MessageExpectation.verify}
|
18
18
|
cls.macspec_superclass = super_class
|
19
|
+
MacSpec.add_test_case(cls)
|
19
20
|
cls.class_eval(&block)
|
20
21
|
cls.testcases.each do |testcase|
|
21
22
|
for test in cls.all_tests.reject {|t| testcase.own_tests.include?(t)}
|
@@ -56,19 +56,16 @@ module MacSpec
|
|
56
56
|
|
57
57
|
# == Define a TestCase.
|
58
58
|
def describe desc, &block
|
59
|
-
cls = Class.new(macspec_superclass)
|
60
|
-
mods = self.ancestors.reject {|m| Module === m }
|
59
|
+
cls = Class.new(self.macspec_superclass)
|
61
60
|
Object.const_set(self.name + desc.to_s.split(/\W+/).map { |s| s.capitalize }.join, cls)
|
62
61
|
cls.setup_chained = self.setup_chained
|
63
62
|
cls.teardown_chained = self.teardown_chained
|
64
63
|
cls.macspec_superclass = self.macspec_superclass
|
65
64
|
cls.desc = self.desc + " " + desc
|
66
|
-
cls.tests($1.constantize) if defined?(Rails) &&
|
67
|
-
self.name =~ /^(.*(Controller|Helper|Mailer))Test/ &&
|
68
|
-
self < ActiveSupport::TestCase
|
69
65
|
mods = self.ancestors.select {|m| m.class.to_s == "Module" }
|
70
66
|
orig_block = block
|
71
|
-
block = lambda {include *mods; instance_eval(&orig_block)}
|
67
|
+
block = lambda {include *mods; instance_eval(&orig_block)}
|
68
|
+
MacSpec.add_test_case(cls)
|
72
69
|
cls.class_eval(&block)
|
73
70
|
self.testcases << cls
|
74
71
|
end
|
@@ -79,12 +76,23 @@ module MacSpec
|
|
79
76
|
desc = MacSpec::TestingFramework::Functions.make_constantizeable(desc)
|
80
77
|
if block_given?
|
81
78
|
test = "test_#{desc.gsub(/\W+/, '_').downcase}"
|
82
|
-
define_method(test, &lambda {
|
79
|
+
define_method(test, &lambda {instance_eval(&block)})
|
83
80
|
(@@_tests ||= []) << test.to_sym
|
84
81
|
(@own_tests ||= []) << test.to_sym
|
85
82
|
end
|
86
83
|
self.teardown {}
|
84
|
+
test.to_sym
|
87
85
|
end
|
86
|
+
|
87
|
+
# == prepend 'f' to focus on a test
|
88
|
+
def fit desc, &block
|
89
|
+
MacSpec.add_focused_test(self, self.it(desc, &block).to_sym)
|
90
|
+
end
|
91
|
+
|
92
|
+
# == prepend 'x' to ignore a test
|
93
|
+
def xit *whatever
|
94
|
+
end
|
95
|
+
|
88
96
|
end # TestCaseClassMethods
|
89
97
|
end
|
90
98
|
end # MacSpec
|
data/lib/mac_spec/version.rb
CHANGED
data/lib/macspec.rb
CHANGED
@@ -22,6 +22,23 @@ module MacSpec
|
|
22
22
|
@current_test_case = tc
|
23
23
|
end
|
24
24
|
|
25
|
+
def add_test_case(tc)
|
26
|
+
(@test_cases ||= []) << tc
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_cases
|
30
|
+
@test_cases
|
31
|
+
end
|
32
|
+
|
33
|
+
def add_focused_test(tc,fit)
|
34
|
+
@focused_tests ||= {}
|
35
|
+
(@focused_tests[tc] ||= []) << fit
|
36
|
+
end
|
37
|
+
|
38
|
+
def focused_tests
|
39
|
+
@focused_tests
|
40
|
+
end
|
41
|
+
|
25
42
|
def assertions_module
|
26
43
|
MiniTest::Assertions
|
27
44
|
end
|
@@ -35,11 +52,55 @@ module MacSpec
|
|
35
52
|
end
|
36
53
|
end
|
37
54
|
end
|
55
|
+
|
56
|
+
# This MonkeyPatch is here, because MacRuby fails to really ignore methods that have
|
57
|
+
# been removed or undefined. The following code snippet will put out *true* with MacRuby
|
58
|
+
# and *false* with other Ruby versions:
|
59
|
+
#
|
60
|
+
# class A
|
61
|
+
# def meth
|
62
|
+
# end
|
63
|
+
# end
|
64
|
+
#
|
65
|
+
# A.send(:remove_method, :meth)
|
66
|
+
# puts A.new.methods.include?(:meth)
|
67
|
+
#
|
68
|
+
#
|
69
|
+
MiniTest::Unit::TestCase.class_eval do
|
70
|
+
def self.test_methods
|
71
|
+
methods = public_instance_methods(true).select{|m|method_defined?(m)}.grep(/^test/).map { |m|
|
72
|
+
m.to_s
|
73
|
+
}.sort
|
74
|
+
|
75
|
+
if self.test_order == :random then
|
76
|
+
max = methods.size
|
77
|
+
methods = methods.sort_by { rand(max) }
|
78
|
+
end
|
79
|
+
|
80
|
+
methods
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
38
84
|
MiniTest::Unit.autorun unless defined?(MacSpecNoAutoRun)
|
39
85
|
require 'mac_spec/version'
|
40
86
|
require 'mac_spec/matcher_system'
|
41
87
|
require 'mac_spec/testing_framework'
|
42
88
|
require 'mac_spec/mocking_framework'
|
89
|
+
|
90
|
+
at_exit do
|
91
|
+
if MacSpec.focused_tests
|
92
|
+
MacSpec.test_cases.each do |testcase|
|
93
|
+
for test in testcase.own_tests
|
94
|
+
unless MacSpec.focused_tests[testcase] && MacSpec.focused_tests[testcase].include?(test)
|
95
|
+
while(testcase.send(:method_defined?, test))
|
96
|
+
testcase.send(:undef_method, test) if testcase.send(:method_defined?, test)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
43
104
|
unless defined?(LOADED)
|
44
105
|
# Track the current testcase and
|
45
106
|
# provide it to the operator matchers and mocking framework.
|
@@ -47,9 +108,9 @@ unless defined?(LOADED)
|
|
47
108
|
# todo no global
|
48
109
|
MacSpec.test_case_class.class_eval do
|
49
110
|
alias_method :old_run_method_aliased_by_macspec, :run
|
50
|
-
def run(
|
111
|
+
def run(runner, *args, &block)
|
51
112
|
MacSpec.current_test_case = self
|
52
|
-
old_run_method_aliased_by_macspec(
|
113
|
+
old_run_method_aliased_by_macspec(runner, *args, &block)
|
53
114
|
end
|
54
115
|
end
|
55
116
|
LOADED = true
|
@@ -7,7 +7,7 @@ describe "Prevent tests from beeing handed down" do
|
|
7
7
|
|
8
8
|
$testcase = self
|
9
9
|
it "does not inherit tests" do
|
10
|
-
$testcase.
|
10
|
+
$testcase.method_defined?(:test_test_it).should be(false)
|
11
11
|
end
|
12
12
|
|
13
13
|
it "doesn't make testname unusable" do
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 4
|
8
|
+
- 0
|
9
|
+
version: 0.4.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Matthias Hennemeyer
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-03-
|
17
|
+
date: 2010-03-07 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|