mspec 1.5.17 → 1.5.18
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/.gitignore +27 -0
- data/Gemfile +4 -0
- data/README +39 -159
- data/Rakefile +4 -44
- data/bin/mkspec.bat +1 -0
- data/bin/mspec-ci.bat +1 -0
- data/bin/mspec-run.bat +1 -0
- data/bin/mspec-tag.bat +1 -0
- data/bin/mspec.bat +1 -0
- data/lib/mspec/commands/mkspec.rb +2 -2
- data/lib/mspec/commands/mspec-run.rb +4 -0
- data/lib/mspec/commands/mspec.rb +18 -3
- data/lib/mspec/guards.rb +1 -0
- data/lib/mspec/guards/block_device.rb +22 -0
- data/lib/mspec/guards/guard.rb +14 -2
- data/lib/mspec/helpers.rb +5 -5
- data/lib/mspec/helpers/const_lookup.rb +6 -1
- data/lib/mspec/helpers/datetime.rb +28 -0
- data/lib/mspec/helpers/ducktype.rb +4 -4
- data/lib/mspec/helpers/environment.rb +19 -2
- data/lib/mspec/helpers/fs.rb +5 -1
- data/lib/mspec/helpers/io.rb +39 -1
- data/lib/mspec/helpers/numeric.rb +89 -0
- data/lib/mspec/helpers/pack.rb +3 -0
- data/lib/mspec/helpers/ruby_exe.rb +53 -15
- data/lib/mspec/helpers/singleton_class.rb +7 -0
- data/lib/mspec/helpers/stasy.rb +33 -0
- data/lib/mspec/helpers/tmp.rb +16 -3
- data/lib/mspec/matchers.rb +8 -0
- data/lib/mspec/matchers/be_computed_by.rb +37 -0
- data/lib/mspec/matchers/be_computed_by_function.rb +35 -0
- data/lib/mspec/matchers/be_nan.rb +20 -0
- data/lib/mspec/matchers/be_valid_dns_name.rb +25 -0
- data/lib/mspec/matchers/have_data.rb +6 -5
- data/lib/mspec/matchers/have_private_method.rb +24 -0
- data/lib/mspec/matchers/have_singleton_method.rb +24 -0
- data/lib/mspec/matchers/infinity.rb +28 -0
- data/lib/mspec/matchers/match_yaml.rb +5 -5
- data/lib/mspec/matchers/raise_error.rb +5 -3
- data/lib/mspec/matchers/signed_zero.rb +28 -0
- data/lib/mspec/mocks/mock.rb +15 -9
- data/lib/mspec/mocks/object.rb +4 -0
- data/lib/mspec/mocks/proxy.rb +26 -1
- data/lib/mspec/runner/actions.rb +0 -1
- data/lib/mspec/runner/context.rb +18 -16
- data/lib/mspec/runner/formatters.rb +2 -0
- data/lib/mspec/runner/formatters/dotted.rb +13 -1
- data/lib/mspec/runner/formatters/junit.rb +96 -0
- data/lib/mspec/runner/formatters/profile.rb +70 -0
- data/lib/mspec/runner/mspec.rb +11 -0
- data/lib/mspec/runner/shared.rb +1 -1
- data/lib/mspec/utils/options.rb +33 -9
- data/lib/mspec/utils/ruby_name.rb +1 -1
- data/lib/mspec/utils/script.rb +2 -1
- data/lib/mspec/version.rb +1 -1
- data/mspec.gemspec +40 -0
- data/spec/commands/mkspec_spec.rb +4 -3
- data/spec/commands/mspec_ci_spec.rb +1 -6
- data/spec/commands/mspec_run_spec.rb +1 -6
- data/spec/commands/mspec_spec.rb +14 -6
- data/spec/commands/mspec_tag_spec.rb +28 -27
- data/spec/expectations/expectations_spec.rb +1 -1
- data/spec/expectations/should_spec.rb +4 -4
- data/spec/guards/background_spec.rb +2 -2
- data/spec/guards/block_device_spec.rb +46 -0
- data/spec/guards/bug_spec.rb +2 -3
- data/spec/guards/compliance_spec.rb +2 -2
- data/spec/guards/conflict_spec.rb +2 -2
- data/spec/guards/endian_spec.rb +2 -2
- data/spec/guards/extensions_spec.rb +2 -2
- data/spec/guards/feature_spec.rb +2 -2
- data/spec/guards/guard_spec.rb +80 -22
- data/spec/guards/noncompliance_spec.rb +2 -2
- data/spec/guards/platform_spec.rb +2 -2
- data/spec/guards/quarantine_spec.rb +2 -2
- data/spec/guards/runner_spec.rb +2 -2
- data/spec/guards/specified_spec.rb +2 -2
- data/spec/guards/superuser_spec.rb +2 -2
- data/spec/guards/support_spec.rb +2 -2
- data/spec/guards/tty_spec.rb +2 -2
- data/spec/guards/user_spec.rb +2 -2
- data/spec/guards/version_spec.rb +2 -2
- data/spec/helpers/argv_spec.rb +3 -2
- data/spec/helpers/const_lookup_spec.rb +3 -2
- data/spec/helpers/datetime_spec.rb +44 -0
- data/spec/helpers/ducktype_spec.rb +3 -2
- data/spec/helpers/encode_spec.rb +3 -2
- data/spec/helpers/enumerator_class_spec.rb +5 -5
- data/spec/helpers/environment_spec.rb +15 -3
- data/spec/helpers/fixture_spec.rb +3 -2
- data/spec/helpers/flunk_spec.rb +4 -3
- data/spec/helpers/fs_spec.rb +35 -18
- data/spec/helpers/hash_spec.rb +3 -2
- data/spec/helpers/io_spec.rb +75 -6
- data/spec/helpers/language_version_spec.rb +3 -2
- data/spec/helpers/mock_to_path_spec.rb +3 -2
- data/spec/helpers/numeric_spec.rb +25 -0
- data/spec/helpers/ruby_exe_spec.rb +115 -29
- data/spec/helpers/scratch_spec.rb +3 -1
- data/spec/helpers/stasy_spec.rb +59 -0
- data/spec/helpers/tmp_spec.rb +21 -4
- data/spec/matchers/base_spec.rb +2 -2
- data/spec/matchers/be_an_instance_of_spec.rb +2 -2
- data/spec/matchers/be_ancestor_of_spec.rb +2 -2
- data/spec/matchers/be_close_spec.rb +2 -2
- data/spec/matchers/be_computed_by_function_spec.rb +36 -0
- data/spec/matchers/be_computed_by_spec.rb +42 -0
- data/spec/matchers/be_empty_spec.rb +2 -2
- data/spec/matchers/be_false_spec.rb +3 -3
- data/spec/matchers/be_kind_of_spec.rb +2 -2
- data/spec/matchers/be_nan_spec.rb +28 -0
- data/spec/matchers/be_nil_spec.rb +3 -3
- data/spec/matchers/be_true_spec.rb +3 -3
- data/spec/matchers/be_valid_dns_name_spec.rb +50 -0
- data/spec/matchers/complain_spec.rb +2 -2
- data/spec/matchers/eql_spec.rb +2 -2
- data/spec/matchers/equal_element_spec.rb +2 -2
- data/spec/matchers/equal_spec.rb +2 -2
- data/spec/matchers/equal_utf16_spec.rb +2 -2
- data/spec/matchers/have_class_variable_spec.rb +3 -3
- data/spec/matchers/have_constant_spec.rb +2 -2
- data/spec/matchers/have_data_spec.rb +8 -5
- data/spec/matchers/have_instance_method_spec.rb +2 -2
- data/spec/matchers/have_instance_variable_spec.rb +3 -3
- data/spec/matchers/have_method_spec.rb +2 -2
- data/spec/matchers/have_private_instance_method_spec.rb +3 -3
- data/spec/matchers/have_private_method_spec.rb +44 -0
- data/spec/matchers/have_protected_instance_method_spec.rb +2 -2
- data/spec/matchers/have_public_instance_method_spec.rb +2 -2
- data/spec/matchers/have_singleton_method_spec.rb +45 -0
- data/spec/matchers/include_spec.rb +2 -2
- data/spec/matchers/infinity_spec.rb +34 -0
- data/spec/matchers/match_yaml_spec.rb +3 -3
- data/spec/matchers/output_spec.rb +2 -2
- data/spec/matchers/output_to_fd_spec.rb +2 -2
- data/spec/matchers/raise_error_spec.rb +24 -3
- data/spec/matchers/respond_to_spec.rb +2 -2
- data/spec/matchers/signed_zero_spec.rb +32 -0
- data/spec/matchers/stringsymboladapter_spec.rb +2 -2
- data/spec/mocks/mock_spec.rb +12 -12
- data/spec/mocks/proxy_spec.rb +1 -1
- data/spec/runner/actions/gdb_spec.rb +1 -1
- data/spec/runner/actions/tag_spec.rb +1 -1
- data/spec/runner/actions/taglist_spec.rb +1 -1
- data/spec/runner/context_spec.rb +27 -27
- data/spec/runner/example_spec.rb +1 -1
- data/spec/runner/exception_spec.rb +1 -1
- data/spec/runner/filters/tag_spec.rb +2 -2
- data/spec/runner/formatters/describe_spec.rb +1 -1
- data/spec/runner/formatters/dotted_spec.rb +2 -2
- data/spec/runner/formatters/html_spec.rb +2 -2
- data/spec/runner/formatters/junit_spec.rb +147 -0
- data/spec/runner/formatters/unit_spec.rb +2 -2
- data/spec/runner/formatters/yaml_spec.rb +3 -3
- data/spec/runner/mspec_spec.rb +22 -21
- data/spec/runner/shared_spec.rb +9 -1
- data/spec/runner/tag_spec.rb +1 -1
- data/spec/spec_helper.rb +1 -7
- data/spec/utils/name_map_spec.rb +1 -2
- data/spec/utils/options_spec.rb +58 -27
- data/spec/utils/script_spec.rb +5 -13
- data/spec/utils/version_spec.rb +1 -1
- metadata +254 -64
- data/lib/mspec/helpers/bignum.rb +0 -5
- data/lib/mspec/helpers/fmode.rb +0 -15
- data/lib/mspec/helpers/infinity.rb +0 -5
- data/lib/mspec/helpers/metaclass.rb +0 -7
- data/lib/mspec/helpers/nan.rb +0 -5
- data/lib/mspec/runner/actions/debug.rb +0 -17
- data/spec/helpers/bignum_spec.rb +0 -11
- data/spec/helpers/fmode_spec.rb +0 -14
- data/spec/helpers/infinity_spec.rb +0 -8
- data/spec/helpers/nan_spec.rb +0 -8
- data/spec/runner/actions/debug_spec.rb +0 -62
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'mspec/guards'
|
|
3
|
+
require 'mspec/helpers'
|
|
4
|
+
|
|
5
|
+
describe Object, "#bignum_value" do
|
|
6
|
+
it "returns a value that is an instance of Bignum on any platform" do
|
|
7
|
+
bignum_value.should == 0x8000_0000_0000_0000
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "returns the default value incremented by the argument" do
|
|
11
|
+
bignum_value(42).should == 0x8000_0000_0000_002a
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
describe Object, "#nan_value" do
|
|
16
|
+
it "returns NaN" do
|
|
17
|
+
nan_value.nan?.should be_true
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
describe Object, "#infinity_value" do
|
|
22
|
+
it "returns Infinity" do
|
|
23
|
+
infinity_value.infinite?.should == 1
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
require
|
|
2
|
-
require 'mspec/
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'mspec/guards'
|
|
3
|
+
require 'mspec/helpers'
|
|
3
4
|
require 'rbconfig'
|
|
4
5
|
|
|
5
6
|
class RubyExeSpecs
|
|
@@ -31,11 +32,6 @@ describe "#ruby_exe_options" do
|
|
|
31
32
|
@script.ruby_exe_options(:env).should == "kowabunga"
|
|
32
33
|
end
|
|
33
34
|
|
|
34
|
-
it "returns 'bin/rbx' when passed :engine and RUBY_NAME is 'rbx'" do
|
|
35
|
-
Object.const_set :RUBY_NAME, 'rbx'
|
|
36
|
-
@script.ruby_exe_options(:engine).should == 'bin/rbx'
|
|
37
|
-
end
|
|
38
|
-
|
|
39
35
|
it "returns 'bin/jruby' when passed :engine and RUBY_NAME is 'jruby'" do
|
|
40
36
|
Object.const_set :RUBY_NAME, 'jruby'
|
|
41
37
|
@script.ruby_exe_options(:engine).should == 'bin/jruby'
|
|
@@ -51,17 +47,46 @@ describe "#ruby_exe_options" do
|
|
|
51
47
|
@script.ruby_exe_options(:engine).should == 'maglev-ruby'
|
|
52
48
|
end
|
|
53
49
|
|
|
50
|
+
it "returns 'topaz' when passed :engine and RUBY_NAME is 'topaz'" do
|
|
51
|
+
Object.const_set :RUBY_NAME, 'topaz'
|
|
52
|
+
@script.ruby_exe_options(:engine).should == 'topaz'
|
|
53
|
+
end
|
|
54
|
+
|
|
54
55
|
it "returns RUBY_NAME + $(EXEEXT) when passed :name" do
|
|
55
|
-
bin = RUBY_NAME + (
|
|
56
|
+
bin = RUBY_NAME + (RbConfig::CONFIG['EXEEXT'] || RbConfig::CONFIG['exeext'] || '')
|
|
56
57
|
name = File.join ".", bin
|
|
57
58
|
@script.ruby_exe_options(:name).should == name
|
|
58
59
|
end
|
|
59
60
|
|
|
60
61
|
it "returns $(bindir)/$(RUBY_INSTALL_NAME) + $(EXEEXT) when passed :install_name" do
|
|
61
|
-
bin =
|
|
62
|
-
name = File.join
|
|
62
|
+
bin = RbConfig::CONFIG['RUBY_INSTALL_NAME'] + (RbConfig::CONFIG['EXEEXT'] || RbConfig::CONFIG['exeext'] || '')
|
|
63
|
+
name = File.join RbConfig::CONFIG['bindir'], bin
|
|
63
64
|
@script.ruby_exe_options(:install_name).should == name
|
|
64
65
|
end
|
|
66
|
+
|
|
67
|
+
describe "under Rubinius" do
|
|
68
|
+
before :each do
|
|
69
|
+
@ruby_version = RUBY_VERSION
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
after :each do
|
|
73
|
+
Object.const_set :RUBY_VERSION, @ruby_version
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
it "returns 'bin/rbx' when passed :engine, RUBY_NAME is 'rbx' and RUBY_VERSION < 1.9" do
|
|
77
|
+
Object.const_set :RUBY_VERSION, "1.8.7"
|
|
78
|
+
Object.const_set :RUBY_NAME, 'rbx'
|
|
79
|
+
|
|
80
|
+
@script.ruby_exe_options(:engine).should == 'bin/rbx'
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it "returns 'bin/rbx -X19' when passed :engine, RUBY_NAME is 'rbx' and RUBY_VERSION >= 1.9" do
|
|
84
|
+
Object.const_set :RUBY_VERSION, "1.9.2"
|
|
85
|
+
Object.const_set :RUBY_NAME, 'rbx'
|
|
86
|
+
|
|
87
|
+
@script.ruby_exe_options(:engine).should == 'bin/rbx -X19'
|
|
88
|
+
end
|
|
89
|
+
end
|
|
65
90
|
end
|
|
66
91
|
|
|
67
92
|
describe "#resolve_ruby_exe" do
|
|
@@ -85,6 +110,7 @@ describe "#resolve_ruby_exe" do
|
|
|
85
110
|
@script.should_receive(:ruby_exe_options).and_return(@name)
|
|
86
111
|
File.should_receive(:exists?).with(@name).and_return(true)
|
|
87
112
|
File.should_receive(:executable?).with(@name).and_return(true)
|
|
113
|
+
File.should_receive(:expand_path).with(@name).and_return(@name)
|
|
88
114
|
@script.resolve_ruby_exe.should == @name
|
|
89
115
|
end
|
|
90
116
|
|
|
@@ -93,16 +119,26 @@ describe "#resolve_ruby_exe" do
|
|
|
93
119
|
@script.should_receive(:ruby_exe_options).and_return(@name)
|
|
94
120
|
File.should_receive(:exists?).with(@name).and_return(true)
|
|
95
121
|
File.should_not_receive(:executable?)
|
|
122
|
+
File.should_receive(:expand_path).with(@name).and_return(@name)
|
|
96
123
|
@script.resolve_ruby_exe.should == @name
|
|
97
124
|
end
|
|
98
125
|
|
|
126
|
+
it "expands the path portion of the result of #ruby_exe_options" do
|
|
127
|
+
PlatformGuard.stub!(:windows?).and_return(false)
|
|
128
|
+
@script.should_receive(:ruby_exe_options).and_return("#{@name} -Xfoo")
|
|
129
|
+
File.should_receive(:exists?).with(@name).and_return(true)
|
|
130
|
+
File.should_receive(:executable?).with(@name).and_return(true)
|
|
131
|
+
File.should_receive(:expand_path).with(@name).and_return("/usr/bin/#{@name}")
|
|
132
|
+
@script.resolve_ruby_exe.should == "/usr/bin/#{@name} -Xfoo"
|
|
133
|
+
end
|
|
134
|
+
|
|
99
135
|
it "returns nil if no exe is found" do
|
|
100
136
|
File.should_receive(:exists?).at_least(:once).and_return(false)
|
|
101
137
|
@script.resolve_ruby_exe.should be_nil
|
|
102
138
|
end
|
|
103
139
|
end
|
|
104
140
|
|
|
105
|
-
describe Object, "#
|
|
141
|
+
describe Object, "#ruby_cmd" do
|
|
106
142
|
before :all do
|
|
107
143
|
@verbose = $VERBOSE
|
|
108
144
|
$VERBOSE = nil
|
|
@@ -125,35 +161,85 @@ describe Object, "#ruby_exe" do
|
|
|
125
161
|
$VERBOSE = @verbose
|
|
126
162
|
end
|
|
127
163
|
|
|
128
|
-
it "
|
|
164
|
+
it "returns a command that runs the given file if it is a file that exists" do
|
|
129
165
|
File.should_receive(:exists?).with(@file).and_return(true)
|
|
130
|
-
@script.
|
|
131
|
-
@script.ruby_exe @file
|
|
166
|
+
@script.ruby_cmd(@file).should == "ruby_spec_exe -w -Q some/ruby/file.rb"
|
|
132
167
|
end
|
|
133
168
|
|
|
134
|
-
it "
|
|
169
|
+
it "includes the given options and arguments with a file" do
|
|
135
170
|
File.should_receive(:exists?).with(@file).and_return(true)
|
|
136
|
-
@script.
|
|
137
|
-
"ruby_spec_exe -w -Q -w -Cdir some/ruby/file.rb < file.txt"
|
|
138
|
-
@script.ruby_exe @file, :options => "-w -Cdir", :args => "< file.txt"
|
|
171
|
+
@script.ruby_cmd(@file, :options => "-w -Cdir", :args => "< file.txt").should ==
|
|
172
|
+
"ruby_spec_exe -w -Q -w -Cdir some/ruby/file.rb < file.txt"
|
|
139
173
|
end
|
|
140
174
|
|
|
141
|
-
it "
|
|
175
|
+
it "returns a command that runs code using -e" do
|
|
142
176
|
File.should_receive(:exists?).with(@code).and_return(false)
|
|
143
|
-
@script.
|
|
144
|
-
%(ruby_spec_exe -w -Q -e "some \\"real\\" 'ruby' code"))
|
|
145
|
-
@script.ruby_exe @code
|
|
177
|
+
@script.ruby_cmd(@code).should == %(ruby_spec_exe -w -Q -e "some \\"real\\" 'ruby' code")
|
|
146
178
|
end
|
|
147
179
|
|
|
148
|
-
it "
|
|
180
|
+
it "includes the given options and arguments with -e" do
|
|
149
181
|
File.should_receive(:exists?).with(@code).and_return(false)
|
|
150
|
-
@script.
|
|
151
|
-
%(ruby_spec_exe -w -Q -W0 -Cdir -e "some \\"real\\" 'ruby' code" < file.txt)
|
|
152
|
-
@script.ruby_exe @code, :options => "-W0 -Cdir", :args => "< file.txt"
|
|
182
|
+
@script.ruby_cmd(@code, :options => "-W0 -Cdir", :args => "< file.txt").should ==
|
|
183
|
+
%(ruby_spec_exe -w -Q -W0 -Cdir -e "some \\"real\\" 'ruby' code" < file.txt)
|
|
153
184
|
end
|
|
154
185
|
|
|
155
|
-
it "
|
|
156
|
-
@script.
|
|
157
|
-
|
|
186
|
+
it "returns a command with options and arguments but without code or file" do
|
|
187
|
+
@script.ruby_cmd(nil, :options => "-c", :args => "> file.txt").should ==
|
|
188
|
+
"ruby_spec_exe -w -Q -c > file.txt"
|
|
189
|
+
end
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
describe Object, "#ruby_exe" do
|
|
193
|
+
before :all do
|
|
194
|
+
@script = RubyExeSpecs.new
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
before :each do
|
|
198
|
+
@script.stub!(:`)
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
it "executes (using `) the result of calling #ruby_cmd with the given arguments" do
|
|
202
|
+
code = "code"
|
|
203
|
+
options = {}
|
|
204
|
+
@script.should_receive(:ruby_cmd).with(code, options).and_return("ruby_cmd")
|
|
205
|
+
@script.should_receive(:`).with("ruby_cmd")
|
|
206
|
+
@script.ruby_exe(code, options)
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
describe "with :dir option" do
|
|
210
|
+
it "executes the command in the given working directory" do
|
|
211
|
+
Dir.should_receive(:chdir).with("tmp")
|
|
212
|
+
@script.ruby_exe nil, :dir => "tmp"
|
|
213
|
+
end
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
describe "with :env option" do
|
|
217
|
+
it "preserves the values of existing ENV keys" do
|
|
218
|
+
ENV["ABC"] = "123"
|
|
219
|
+
ENV.should_receive(:[]).with("RUBY_FLAGS")
|
|
220
|
+
ENV.should_receive(:[]).with("ABC")
|
|
221
|
+
@script.ruby_exe nil, :env => { :ABC => "xyz" }
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
it "adds the :env entries to ENV" do
|
|
225
|
+
ENV.should_receive(:[]=).with("ABC", "xyz")
|
|
226
|
+
@script.ruby_exe nil, :env => { :ABC => "xyz" }
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
it "deletes the :env entries in ENV when an exception is raised" do
|
|
230
|
+
ENV.should_receive(:delete).with("XYZ")
|
|
231
|
+
@script.ruby_exe nil, :env => { :XYZ => "xyz" }
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
it "resets the values of existing ENV keys when an exception is raised" do
|
|
235
|
+
ENV["ABC"] = "123"
|
|
236
|
+
ENV.should_receive(:[]=).with("ABC", "xyz")
|
|
237
|
+
ENV.should_receive(:[]=).with("ABC", "123")
|
|
238
|
+
|
|
239
|
+
@script.should_receive(:`).and_raise(Exception)
|
|
240
|
+
lambda do
|
|
241
|
+
@script.ruby_exe nil, :env => { :ABC => "xyz" }
|
|
242
|
+
end.should raise_error(Exception)
|
|
243
|
+
end
|
|
158
244
|
end
|
|
159
245
|
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'mspec/guards'
|
|
3
|
+
require 'mspec/helpers'
|
|
4
|
+
|
|
5
|
+
describe Object, "#stasy when RUBY_VERSION < 1.9" do
|
|
6
|
+
before :all do
|
|
7
|
+
@ruby_version = Object.const_get :RUBY_VERSION
|
|
8
|
+
|
|
9
|
+
Object.const_set :RUBY_VERSION, "1.8.7"
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
after :all do
|
|
13
|
+
Object.const_set :RUBY_VERSION, @ruby_version
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "returns a String when passed a String" do
|
|
17
|
+
stasy("nom").should == "nom"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "returns a String when passed a Symbol" do
|
|
21
|
+
stasy(:some).should == "some"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "returns an Array of Strings when passed an Array of Strings" do
|
|
25
|
+
stasy("nom", "nom").should == ["nom", "nom"]
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "returns an Array of Strings when passed an Array of Symbols" do
|
|
29
|
+
stasy(:some, :thing).should == ["some", "thing"]
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
describe Object, "#stasy when RUBY_VERSION >= 1.9.0" do
|
|
34
|
+
before :all do
|
|
35
|
+
@ruby_version = Object.const_get :RUBY_VERSION
|
|
36
|
+
|
|
37
|
+
Object.const_set :RUBY_VERSION, "1.9.0"
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
after :all do
|
|
41
|
+
Object.const_set :RUBY_VERSION, @ruby_version
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it "returns a Symbol when passed a String" do
|
|
45
|
+
stasy("nom").should == :nom
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it "returns a Symbol when passed a Symbol" do
|
|
49
|
+
stasy(:some).should == :some
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it "returns an Array of Symbols when passed an Array of Strings" do
|
|
53
|
+
stasy("some", "thing").should == [:some, :thing]
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it "returns an Array of Symbols when passed an Array of Symbols" do
|
|
57
|
+
stasy(:nom, :nom).should == [:nom, :nom]
|
|
58
|
+
end
|
|
59
|
+
end
|
data/spec/helpers/tmp_spec.rb
CHANGED
|
@@ -1,10 +1,27 @@
|
|
|
1
|
-
require
|
|
2
|
-
require 'mspec/
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'mspec/guards'
|
|
3
|
+
require 'mspec/helpers'
|
|
3
4
|
|
|
4
5
|
describe Object, "#tmp" do
|
|
6
|
+
before :all do
|
|
7
|
+
@dir = "#{File.expand_path(Dir.pwd)}/rubyspec_temp"
|
|
8
|
+
end
|
|
9
|
+
|
|
5
10
|
it "returns a name relative to the current working directory" do
|
|
6
|
-
|
|
11
|
+
tmp("test.txt").should == "#{@dir}/#{SPEC_TEMP_UNIQUIFIER}-test.txt"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "returns a 'unique' name on repeated calls" do
|
|
15
|
+
a = tmp("text.txt")
|
|
16
|
+
b = tmp("text.txt")
|
|
17
|
+
a.should_not == b
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "does not 'uniquify' the name if requested not to" do
|
|
21
|
+
tmp("test.txt", false).should == "#{@dir}/test.txt"
|
|
22
|
+
end
|
|
7
23
|
|
|
8
|
-
|
|
24
|
+
it "returns the name of the temporary directory when passed an empty string" do
|
|
25
|
+
tmp("").should == "#{@dir}/"
|
|
9
26
|
end
|
|
10
27
|
end
|
data/spec/matchers/base_spec.rb
CHANGED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'mspec/matchers'
|
|
3
|
+
|
|
4
|
+
describe BeComputedByFunctionMatcher do
|
|
5
|
+
it "matches when all entries in the Array compute" do
|
|
6
|
+
array = [ ["%2d", 65, "65"],
|
|
7
|
+
["%04d", 90, "0090"] ]
|
|
8
|
+
BeComputedByFunctionMatcher.new(:sprintf).matches?(array).should be_true
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "matches when all entries in the Array with arguments compute" do
|
|
12
|
+
array = [ ["%2d", "65"],
|
|
13
|
+
["%04d", "0065"] ]
|
|
14
|
+
BeComputedByFunctionMatcher.new(:sprintf, 65).matches?(array).should be_true
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "does not match when any entry in the Array does not compute" do
|
|
18
|
+
array = [ ["%2d", 65, "65"],
|
|
19
|
+
["%04d", 90, "00090"] ]
|
|
20
|
+
BeComputedByFunctionMatcher.new(:sprintf).matches?(array).should be_false
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "does not match when any entry in the Array with arguments does not compute" do
|
|
24
|
+
array = [ ["%2d", "65"],
|
|
25
|
+
["%04d", "0065"] ]
|
|
26
|
+
BeComputedByFunctionMatcher.new(:sprintf, 91).matches?(array).should be_false
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "provides a useful failure message" do
|
|
30
|
+
array = [ ["%2d", 90, "65"],
|
|
31
|
+
["%04d", 90, "00090"] ]
|
|
32
|
+
matcher = BeComputedByFunctionMatcher.new(:sprintf)
|
|
33
|
+
matcher.matches?(array)
|
|
34
|
+
matcher.failure_message.should == ["Expected \"65\"", "to be computed by sprintf(\"%2d\", 90)"]
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'mspec/matchers'
|
|
3
|
+
|
|
4
|
+
describe BeComputedByMatcher do
|
|
5
|
+
it "matches when all entries in the Array compute" do
|
|
6
|
+
array = [ [65, "A"],
|
|
7
|
+
[90, "Z"] ]
|
|
8
|
+
BeComputedByMatcher.new(:chr).matches?(array).should be_true
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "matches when all entries in the Array with arguments compute" do
|
|
12
|
+
array = [ [1, 2, 3],
|
|
13
|
+
[2, 4, 6] ]
|
|
14
|
+
BeComputedByMatcher.new(:+).matches?(array).should be_true
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "does not match when any entry in the Array does not compute" do
|
|
18
|
+
array = [ [65, "A" ],
|
|
19
|
+
[91, "Z" ] ]
|
|
20
|
+
BeComputedByMatcher.new(:chr).matches?(array).should be_false
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "accepts an argument list to apply to each method call" do
|
|
24
|
+
array = [ [65, "1000001" ],
|
|
25
|
+
[90, "1011010" ] ]
|
|
26
|
+
BeComputedByMatcher.new(:to_s, 2).matches?(array).should be_true
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "does not match when any entry in the Array with arguments does not compute" do
|
|
30
|
+
array = [ [1, 2, 3],
|
|
31
|
+
[2, 4, 7] ]
|
|
32
|
+
BeComputedByMatcher.new(:+).matches?(array).should be_false
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "provides a useful failure message" do
|
|
36
|
+
array = [ [65, "A" ],
|
|
37
|
+
[91, "Z" ] ]
|
|
38
|
+
matcher = BeComputedByMatcher.new(:chr)
|
|
39
|
+
matcher.matches?(array)
|
|
40
|
+
matcher.failure_message.should == ["Expected \"Z\"", "to be computed by 91.chr (computed \"[\" instead)"]
|
|
41
|
+
end
|
|
42
|
+
end
|