Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/mspec/helpers/tmp.rb,
lib/mspec/guards/bug.rb,
lib/mspec/matchers/eql.rb,
lib/mspec/mocks/object.rb,
lib/mspec/guards/endian.rb,
lib/mspec/guards/runner.rb,
lib/mspec/helpers/flunk.rb,
lib/mspec/runner/object.rb,
lib/mspec/runner/shared.rb,
lib/mspec/guards/support.rb,
lib/mspec/guards/version.rb,
lib/mspec/helpers/bignum.rb,
lib/mspec/matchers/equal.rb,
lib/mspec/guards/conflict.rb,
lib/mspec/guards/platform.rb,
lib/mspec/matchers/be_nil.rb,
lib/mspec/matchers/output.rb,
lib/mspec/guards/superuser.rb,
lib/mspec/helpers/ruby_exe.rb,
lib/mspec/matchers/be_true.rb,
lib/mspec/guards/compliance.rb,
lib/mspec/guards/extensions.rb,
lib/mspec/guards/quarantine.rb,
lib/mspec/matchers/be_close.rb,
lib/mspec/matchers/be_empty.rb,
lib/mspec/matchers/be_false.rb,
lib/mspec/matchers/complain.rb,
lib/mspec/expectations/should.rb,
lib/mspec/matchers/be_kind_of.rb,
lib/mspec/matchers/match_yaml.rb,
lib/mspec/matchers/respond_to.rb,
lib/mspec/guards/noncompliance.rb,
lib/mspec/matchers/equal_utf16.rb,
lib/mspec/matchers/raise_error.rb,
lib/mspec/matchers/output_to_fd.rb,
lib/mspec/matchers/equal_element.rb,
lib/mspec/matchers/be_ancestor_of.rb
Overview
The ruby_exe helper provides a wrapper for invoking the same Ruby interpreter as the one running the specs and getting the output from running the code. If code
is a file that exists, it will be run. Otherwise, code
should be Ruby code that will be run with the -e command line option. For example:
ruby_exe('path/to/some/file.rb')
will be executed as
`#{RUBY_EXE} #{'path/to/some/file.rb'}`
while
ruby_exe('puts "hello, world."')
will be executed as
`#{RUBY_EXE} -e #{'puts "hello, world."'}`
The RUBY_EXE constant can be set explicitly since the value is used each time ruby_exe is invoked. The mspec runner script will set ENV to the name of the executable used to invoke the mspec-run script. The value of RUBY_EXE will be constructed as follows:
1. the value of ENV['RUBY_EXE']
2. an explicit value based on RUBY_NAME
3. cwd/(RUBY_NAME + $(EXEEXT) || $(exeext) || '')
4. $(bindir)/$(RUBY_INSTALL_NAME)
The value will only be used if the file exists and is executable.
These 4 ways correspond to the following scenarios:
1. Using the MSpec runner scripts, the name of the
executable is explicitly passed by ENV['RUBY_EXE']
so there is no ambiguity.
Otherwise, if using RSpec (or something else)
2. Running the specs while developing an alternative
Ruby implementation. This explicitly names the
executable in the development directory based on
the value of RUBY_NAME, which is probably initialized
from the value of RUBY_ENGINE.
3. Running the specs within the source directory for
some implementation. (E.g. a local build directory.)
4. Running the specs against some installed Ruby
implementation.
Instance Method Summary collapse
- #after(at = :each, &block) ⇒ Object
- #as_superuser ⇒ Object
- #be_ancestor_of(expected) ⇒ Object
- #be_close(expected, tolerance) ⇒ Object
- #be_empty ⇒ Object
- #be_false ⇒ Object
- #be_kind_of(expected) ⇒ Object
- #be_nil ⇒ Object
- #be_true ⇒ Object
- #before(at = :each, &block) ⇒ Object
- #big_endian ⇒ Object
- #bignum_value(plus = 0) ⇒ Object
- #complain(complaint = nil) ⇒ Object
- #compliant_on(*args) ⇒ Object
- #conflicts_with(*modules) ⇒ Object
- #describe(mod, msg = nil, options = nil, &block) ⇒ Object (also: #context)
- #deviates_on(*args) ⇒ Object
- #eql(expected) ⇒ Object
- #equal(expected) ⇒ Object
- #equal_element(*args) ⇒ Object
- #equal_utf16(expected) ⇒ Object
- #extended_on(*args) ⇒ Object
- #flunk ⇒ Object
- #it(msg, &block) ⇒ Object (also: #specify)
- #it_behaves_like(desc, meth, obj = nil) ⇒ Object
- #it_should_behave_like(desc) ⇒ Object
- #little_endian ⇒ Object
- #match_yaml(expected) ⇒ Object
- #mock(name, options = {}) ⇒ Object
- #not_compliant_on(*args) ⇒ Object
- #not_supported_on(*args) ⇒ Object
- #output(stdout = nil, stderr = nil) ⇒ Object
- #output_to_fd(what, where = STDOUT) ⇒ Object
- #platform_is(*args) ⇒ Object
- #platform_is_not(*args) ⇒ Object
- #quarantine! ⇒ Object
- #raise_error(exception = Exception, message = nil, &block) ⇒ Object
- #resolve_ruby_exe ⇒ Object
- #respond_to(expected) ⇒ Object
- #ruby_bug(bug = "Please add a bug tracker number", version = "0") ⇒ Object
- #ruby_exe(code) ⇒ Object
- #ruby_exe_options(option) ⇒ Object
- #ruby_version_is(*args) ⇒ Object
- #runner_is(*args) ⇒ Object
- #runner_is_not(*args) ⇒ Object
- #should(matcher = nil) ⇒ Object
- #should_not(matcher = nil) ⇒ Object
- #should_not_receive(sym) ⇒ Object
- #should_receive(sym) ⇒ Object
- #stub!(sym) ⇒ Object
- #tmp(name) ⇒ Object
Instance Method Details
#after(at = :each, &block) ⇒ Object
6 7 8 |
# File 'lib/mspec/runner/object.rb', line 6 def after(at=:each, &block) MSpec.current.after at, &block end |
#as_superuser ⇒ Object
10 11 12 13 14 |
# File 'lib/mspec/guards/superuser.rb', line 10 def as_superuser g = SuperUserGuard.new yield if g.yield? g.unregister end |
#be_ancestor_of(expected) ⇒ Object
21 22 23 |
# File 'lib/mspec/matchers/be_ancestor_of.rb', line 21 def be_ancestor_of(expected) BeAncestorOfMatcher.new(expected) end |
#be_close(expected, tolerance) ⇒ Object
24 25 26 |
# File 'lib/mspec/matchers/be_close.rb', line 24 def be_close(expected, tolerance) BeCloseMatcher.new(expected, tolerance) end |
#be_empty ⇒ Object
17 18 19 |
# File 'lib/mspec/matchers/be_empty.rb', line 17 def be_empty BeEmptyMatcher.new end |
#be_false ⇒ Object
17 18 19 |
# File 'lib/mspec/matchers/be_false.rb', line 17 def be_false BeFalseMatcher.new end |
#be_kind_of(expected) ⇒ Object
21 22 23 |
# File 'lib/mspec/matchers/be_kind_of.rb', line 21 def be_kind_of(expected) BeKindOfMatcher.new(expected) end |
#be_nil ⇒ Object
17 18 19 |
# File 'lib/mspec/matchers/be_nil.rb', line 17 def be_nil BeNilMatcher.new end |
#be_true ⇒ Object
17 18 19 |
# File 'lib/mspec/matchers/be_true.rb', line 17 def be_true BeTrueMatcher.new end |
#before(at = :each, &block) ⇒ Object
2 3 4 |
# File 'lib/mspec/runner/object.rb', line 2 def before(at=:each, &block) MSpec.current.before at, &block end |
#big_endian ⇒ Object
29 30 31 32 33 |
# File 'lib/mspec/guards/endian.rb', line 29 def big_endian g = BigEndianGuard.new yield if g.yield? g.unregister end |
#bignum_value(plus = 0) ⇒ Object
2 3 4 |
# File 'lib/mspec/helpers/bignum.rb', line 2 def bignum_value(plus=0) 0x8000_0000_0000_0000 + plus end |
#complain(complaint = nil) ⇒ Object
53 54 55 |
# File 'lib/mspec/matchers/complain.rb', line 53 def complain(complaint=nil) ComplainMatcher.new(complaint) end |
#compliant_on(*args) ⇒ Object
7 8 9 10 11 |
# File 'lib/mspec/guards/compliance.rb', line 7 def compliant_on(*args) g = ComplianceGuard.new(*args) yield if g.yield? g.unregister end |
#conflicts_with(*modules) ⇒ Object
11 12 13 14 15 |
# File 'lib/mspec/guards/conflict.rb', line 11 def conflicts_with(*modules) g = ConflictsGuard.new(*modules) yield if g.yield? true g.unregister end |
#describe(mod, msg = nil, options = nil, &block) ⇒ Object Also known as: context
10 11 12 |
# File 'lib/mspec/runner/object.rb', line 10 def describe(mod, msg=nil, =nil, &block) MSpec.describe mod, msg, &block end |
#deviates_on(*args) ⇒ Object
7 8 9 10 11 |
# File 'lib/mspec/guards/noncompliance.rb', line 7 def deviates_on(*args) g = NonComplianceGuard.new(*args) yield if g.yield? g.unregister end |
#eql(expected) ⇒ Object
23 24 25 |
# File 'lib/mspec/matchers/eql.rb', line 23 def eql(expected) EqlMatcher.new(expected) end |
#equal(expected) ⇒ Object
23 24 25 |
# File 'lib/mspec/matchers/equal.rb', line 23 def equal(expected) EqualMatcher.new(expected) end |
#equal_element(*args) ⇒ Object
75 76 77 |
# File 'lib/mspec/matchers/equal_element.rb', line 75 def equal_element(*args) EqualElementMatcher.new(*args) end |
#equal_utf16(expected) ⇒ Object
31 32 33 |
# File 'lib/mspec/matchers/equal_utf16.rb', line 31 def equal_utf16(expected) EqualUtf16Matcher.new(expected) end |
#extended_on(*args) ⇒ Object
7 8 9 10 11 |
# File 'lib/mspec/guards/extensions.rb', line 7 def extended_on(*args) g = ExtensionsGuard.new(*args) yield if g.yield? g.unregister end |
#flunk ⇒ Object
2 3 4 |
# File 'lib/mspec/helpers/flunk.rb', line 2 def flunk Expectation.fail_with "This example", "is a failure" end |
#it(msg, &block) ⇒ Object Also known as: specify
14 15 16 |
# File 'lib/mspec/runner/object.rb', line 14 def it(msg, &block) MSpec.current.it msg, &block end |
#it_behaves_like(desc, meth, obj = nil) ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/mspec/runner/shared.rb', line 4 def it_behaves_like(desc, meth, obj=nil) send :before, :all do @method = meth @object = obj if obj end send :it_should_behave_like, desc.to_s end |
#it_should_behave_like(desc) ⇒ Object
18 19 20 |
# File 'lib/mspec/runner/object.rb', line 18 def it_should_behave_like(desc) MSpec.current.it_should_behave_like desc end |
#little_endian ⇒ Object
35 36 37 38 39 |
# File 'lib/mspec/guards/endian.rb', line 35 def little_endian g = LittleEndianGuard.new yield if g.yield? g.unregister end |
#match_yaml(expected) ⇒ Object
43 44 45 |
# File 'lib/mspec/matchers/match_yaml.rb', line 43 def match_yaml(expected) MatchYAMLMatcher.new(expected) end |
#mock(name, options = {}) ⇒ Object
17 18 19 |
# File 'lib/mspec/mocks/object.rb', line 17 def mock(name, ={}) MockObject.new name, end |
#not_compliant_on(*args) ⇒ Object
13 14 15 16 17 |
# File 'lib/mspec/guards/compliance.rb', line 13 def not_compliant_on(*args) g = ComplianceGuard.new(*args) yield if g.yield? true g.unregister end |
#not_supported_on(*args) ⇒ Object
7 8 9 10 11 |
# File 'lib/mspec/guards/support.rb', line 7 def not_supported_on(*args) g = SupportedGuard.new(*args) yield if g.yield? true g.unregister end |
#output(stdout = nil, stderr = nil) ⇒ Object
64 65 66 |
# File 'lib/mspec/matchers/output.rb', line 64 def output(stdout=nil, stderr=nil) OutputMatcher.new(stdout, stderr) end |
#output_to_fd(what, where = STDOUT) ⇒ Object
68 69 70 |
# File 'lib/mspec/matchers/output_to_fd.rb', line 68 def output_to_fd(what, where = STDOUT) OutputToFDMatcher.new what, where end |
#platform_is(*args) ⇒ Object
27 28 29 30 31 |
# File 'lib/mspec/guards/platform.rb', line 27 def platform_is(*args) g = PlatformGuard.new(*args) yield if g.yield? g.unregister end |
#platform_is_not(*args) ⇒ Object
33 34 35 36 37 |
# File 'lib/mspec/guards/platform.rb', line 33 def platform_is_not(*args) g = PlatformGuard.new(*args) yield if g.yield? true g.unregister end |
#quarantine! ⇒ Object
10 11 12 13 14 |
# File 'lib/mspec/guards/quarantine.rb', line 10 def quarantine! g = QuarantineGuard.new yield if g.yield? g.unregister end |
#raise_error(exception = Exception, message = nil, &block) ⇒ Object
45 46 47 |
# File 'lib/mspec/matchers/raise_error.rb', line 45 def raise_error(exception=Exception, =nil, &block) RaiseErrorMatcher.new(exception, , &block) end |
#resolve_ruby_exe ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/mspec/helpers/ruby_exe.rb', line 79 def resolve_ruby_exe [:env, :engine, :name, :install_name].each do |option| exe = option return exe if exe and File.exists?(exe) and File.executable?(exe) end nil end |
#respond_to(expected) ⇒ Object
21 22 23 |
# File 'lib/mspec/matchers/respond_to.rb', line 21 def respond_to(expected) RespondToMatcher.new(expected) end |
#ruby_bug(bug = "Please add a bug tracker number", version = "0") ⇒ Object
22 23 24 25 26 |
# File 'lib/mspec/guards/bug.rb', line 22 def ruby_bug(bug="Please add a bug tracker number", version="0") g = BugGuard.new bug, version yield if g.yield? true g.unregister end |
#ruby_exe(code) ⇒ Object
87 88 89 90 91 92 93 |
# File 'lib/mspec/helpers/ruby_exe.rb', line 87 def ruby_exe(code) if File.exists?(code) and File.executable?(code) `#{RUBY_EXE} #{ENV['RUBY_FLAGS']} #{code}` else `#{RUBY_EXE} #{ENV['RUBY_FLAGS']} -e #{code.inspect}` end end |
#ruby_exe_options(option) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/mspec/helpers/ruby_exe.rb', line 56 def (option) case option when :env ENV['RUBY_EXE'] when :engine case RUBY_NAME when 'rbx' "bin/rbx" when 'jruby' "bin/jruby" when 'ironruby' "ir" end when :name bin = RUBY_NAME + (Config::CONFIG['EXEEXT'] || Config::CONFIG['exeext'] || '') File.join(".", bin) when :install_name bin = Config::CONFIG["RUBY_INSTALL_NAME"] || Config::CONFIG["ruby_install_name"] bin << (Config::CONFIG['EXEEXT'] || Config::CONFIG['exeext'] || '') File.join(Config::CONFIG['bindir'], bin) end end |
#ruby_version_is(*args) ⇒ Object
35 36 37 38 39 |
# File 'lib/mspec/guards/version.rb', line 35 def ruby_version_is(*args) g = VersionGuard.new(*args) yield if g.yield? g.unregister end |
#runner_is(*args) ⇒ Object
19 20 21 22 23 |
# File 'lib/mspec/guards/runner.rb', line 19 def runner_is(*args) g = RunnerGuard.new(*args) yield if g.yield? g.unregister end |
#runner_is_not(*args) ⇒ Object
25 26 27 28 29 |
# File 'lib/mspec/guards/runner.rb', line 25 def runner_is_not(*args) g = RunnerGuard.new(*args) yield if g.yield? true g.unregister end |
#should(matcher = nil) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 |
# File 'lib/mspec/expectations/should.rb', line 2 def should(matcher=nil) MSpec.expectation MSpec.actions :expectation, MSpec.current.state if matcher unless matcher.matches?(self) Expectation.fail_with(*matcher.) end else PositiveOperatorMatcher.new(self) end end |
#should_not(matcher = nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/mspec/expectations/should.rb', line 14 def should_not(matcher=nil) MSpec.expectation MSpec.actions :expectation, MSpec.current.state if matcher if matcher.matches?(self) Expectation.fail_with(*matcher.) end else NegativeOperatorMatcher.new(self) end end |
#should_not_receive(sym) ⇒ Object
12 13 14 15 |
# File 'lib/mspec/mocks/object.rb', line 12 def should_not_receive(sym) proxy = Mock.install_method self, sym proxy.exactly(0).times end |
#should_receive(sym) ⇒ Object
8 9 10 |
# File 'lib/mspec/mocks/object.rb', line 8 def should_receive(sym) Mock.install_method self, sym end |
#stub!(sym) ⇒ Object
4 5 6 |
# File 'lib/mspec/mocks/object.rb', line 4 def stub!(sym) Mock.install_method self, sym, :stub end |
#tmp(name) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/mspec/helpers/tmp.rb', line 17 def tmp(name) unless @spec_temp_directory [ "/private/tmp", "/tmp", "/var/tmp", ENV["TMPDIR"], ENV["TMP"], ENV["TEMP"], ENV["USERPROFILE"] ].each do |dir| if dir and File.directory?(dir) and File.writable?(dir) temp = File. dir temp = File.readlink temp if File.symlink? temp @spec_temp_directory = temp break end end end File.join @spec_temp_directory, name end |