Module: Given

Defined in:
lib/given/failure.rb,
lib/given/version.rb,
lib/given/evaluator.rb,
lib/given/rspec/all.rb,
lib/given/assertions.rb,
lib/given/extensions.rb,
lib/given/file_cache.rb,
lib/given/ext/numeric.rb,
lib/given/fuzzy_number.rb,
lib/given/line_extractor.rb,
lib/given/module_methods.rb,
lib/given/failure_matcher.rb,
lib/given/binary_operation.rb,
lib/given/natural_assertion.rb,
lib/given/minitest/failure_must_raise.rb

Defined Under Namespace

Modules: Assertions, ClassExtensions, Ext, FailureMethod, Fuzzy, InstanceExtensions Classes: BinaryOperation, EvalErr, Evaluator, Failure, FailureMatcher, FileCache, LineExtractor, NaturalAssertion

Constant Summary collapse

VERSION_NUMBERS =
[
  VERSION_MAJOR = 3,
  VERSION_MINOR = 5,
  VERSION_BUILD = 3,
]
VERSION =
VERSION_NUMBERS.join(".")
RBX_IN_USE =

Does this platform support natural assertions?

(RUBY_ENGINE) && RUBY_ENGINE == 'rbx')
JRUBY_IN_USE =
defined?(JRUBY_VERSION)
OLD_JRUBY_IN_USE =
JRUBY_IN_USE && (JRUBY_VERSION < '1.7.5')
NATURAL_ASSERTIONS_SUPPORTED =
! (OLD_JRUBY_IN_USE || RBX_IN_USE)
InvalidThenError =
Class.new(StandardError)

Class Method Summary collapse

Class Method Details

.count_assertion(*args) ⇒ Object

Increment the number of assertions made in the framework.



74
75
76
# File 'lib/given/module_methods.rb', line 74

def self.count_assertion(*args)
  Given.framework.count_assertion(*args)
end

.explicit_assertions?(*args) ⇒ Boolean

Were there any explicit framework assertions made during the execution of the Then block?

Returns:

  • (Boolean)


69
70
71
# File 'lib/given/module_methods.rb', line 69

def self.explicit_assertions?(*args)
  Given.framework.explicit_assertions?(*args)
end

.fail_with(*args) ⇒ Object

Fail an example with the given messages.



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

def self.fail_with(*args)
  Given.framework.fail_with(*args)
end

.frameworkObject



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

def self.framework
  @_gvn_framework
end

.framework=(framework) ⇒ Object



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

def self.framework=(framework)
  @_gvn_framework = framework
end

.location_of(block) ⇒ Object

Return file and line number where the block is defined.



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

def self.location_of(block)
  eval "[__FILE__, __LINE__]", block.binding
end

.natural_assertions_enabled?Boolean

TRUE if natural assertions are globally enabled?

Returns:

  • (Boolean)


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

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.



44
45
46
47
48
# File 'lib/given/module_methods.rb', line 44

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 the current framework to indicate a pending example.



80
81
82
# File 'lib/given/module_methods.rb', line 80

def self.pending_error
  Given.framework.pending_error
end

.source_caching_disabledObject



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

def self.source_caching_disabled
  @_gvn_source_caching_disabled
end

.source_caching_disabled=(value) ⇒ Object



22
23
24
# File 'lib/given/module_methods.rb', line 22

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

.start_evaluation(*args) ⇒ Object

Mark the start of a Then assertion evaluation.



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

def self.start_evaluation(*args)
  Given.framework.start_evaluation(*args)
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.



30
31
32
33
# File 'lib/given/module_methods.rb', line 30

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

.using_old_rspec?Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
# File 'lib/given/rspec/all.rb', line 21

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