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 = 0,
]
VERSION =
VERSION_NUMBERS.join(".")
NATURAL_ASSERTIONS_SUPPORTED =

Does this platform support natural assertions?

! defined?(JRUBY_VERSION)
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.



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

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.



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

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

.matcher_calledObject



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

def self.matcher_called
  @_matcher_called
end

.matcher_called=(value) ⇒ Object



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

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

.natural_assertions_enabled?Boolean

TRUE if natural assertions are globally enabled?

Returns:

  • (Boolean)


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

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.



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

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.



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

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

.source_caching_disabledObject



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

def self.source_caching_disabled
  @_rg_source_caching_disabled
end

.source_caching_disabled=(value) ⇒ Object



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

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.



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

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