Module: RSpec::Given

Defined in:
lib/rspec/given.rb,
lib/rspec/given/failure.rb,
lib/rspec/given/version.rb,
lib/rspec/given/extensions.rb,
lib/rspec/given/file_cache.rb,
lib/rspec/given/ext/numeric.rb,
lib/rspec/given/have_failed.rb,
lib/rspec/given/fuzzy_number.rb,
lib/rspec/given/line_extractor.rb,
lib/rspec/given/module_methods.rb,
lib/rspec/given/natural_assertion.rb

Defined Under Namespace

Modules: ClassExtensions, Ext, Fuzzy, HaveFailed, InstanceExtensions Classes: EvalErr, Failure, FileCache, LineExtractor, NaturalAssertion

Constant Summary collapse

MONKEY =
false
VERSION_NUMBERS =
[
  VERSION_MAJOR = 2,
  VERSION_MINOR = 4,
  VERSION_BUILD = 1,
]
VERSION =
VERSION_NUMBERS.join(".")
RBX_IN_USE =

Does this platform support natural assertions?

(RUBY_ENGINE) && RUBY_ENGINE == 'rbx')
NATURAL_ASSERTIONS_SUPPORTED =
! defined?(JRUBY_VERSION) && ! RBX_IN_USE
InvalidThenError =
Class.new(StandardError)

Class Method Summary collapse

Class Method Details

.detect_formatters(c) ⇒ Object

Detect the formatting requested in the given configuration object.

If the format requires it, source caching will be enabled.



26
27
28
29
# File 'lib/rspec/given/module_methods.rb', line 26

def self.detect_formatters(c)
  format_active = c.formatters.any? { |f| f.class.name !~ /ProgressFormatter/ }
  RSpec::Given.source_caching_disabled = ! format_active
end

.fail_with(*args) ⇒ Object

Fail an example with the given messages.

This should be the only place we reference the RSpec function. Everywhere else in rspec-given should be calling this function.



59
60
61
# File 'lib/rspec/given/module_methods.rb', line 59

def self.fail_with(*args)
  ::RSpec::Expectations.fail_with(*args)
end

.matcher_calledObject



7
8
9
# File 'lib/rspec/given/module_methods.rb', line 7

def self.matcher_called
  @_matcher_called
end

.matcher_called=(value) ⇒ Object



11
12
13
# File 'lib/rspec/given/module_methods.rb', line 11

def self.matcher_called=(value)
  @_matcher_called = value
end

.natural_assertions_enabled?Boolean

TRUE if natural assertions are globally enabled?

Returns:

  • (Boolean)


41
42
43
# File 'lib/rspec/given/module_methods.rb', line 41

def self.natural_assertions_enabled?
  @natural_assertions_enabled
end

.ok_to_use_natural_assertions(enabled) ⇒ Object

Is is OK to use natural assertions on this platform.

An error is raised if the the platform does not support natural assertions and the flag is attempting to enable them.



49
50
51
52
53
# File 'lib/rspec/given/module_methods.rb', line 49

def self.ok_to_use_natural_assertions(enabled)
  if enabled && ! NATURAL_ASSERTIONS_SUPPORTED
    fail ArgumentError, "Natural Assertions are disabled for JRuby"
  end
end

.pending_errorObject

Error object used by RSpec to indicate a pending example.



64
65
66
# File 'lib/rspec/given/module_methods.rb', line 64

def self.pending_error
  RSpec::Core::Pending::PendingDeclaredInExample
end

.source_caching_disabledObject



15
16
17
# File 'lib/rspec/given/module_methods.rb', line 15

def self.source_caching_disabled
  @_rg_source_caching_disabled
end

.source_caching_disabled=(value) ⇒ Object



19
20
21
# File 'lib/rspec/given/module_methods.rb', line 19

def self.source_caching_disabled=(value)
  @_rg_source_caching_disabled = value
end

.use_natural_assertions(enabled = true) ⇒ Object

Globally enable/disable natural assertions.

There is a similar function in Extensions that works at a describe or context scope.



35
36
37
38
# File 'lib/rspec/given/module_methods.rb', line 35

def self.use_natural_assertions(enabled=true)
  ok_to_use_natural_assertions(enabled)
  @natural_assertions_enabled = enabled
end

.using_old_rspec?Boolean

Returns:

  • (Boolean)


3
4
5
6
7
8
# File 'lib/rspec/given.rb', line 3

def self.using_old_rspec?
  defined?(Spec) &&
    defined?(Spec::VERSION) &&
    defined?(Spec::VERSION::SUMMARY) &&
    Spec::VERSION::SUMMARY =~ /^rspec +1\./
end