Module: Given

Defined in:
lib/given/minitest/before_extension.rb,
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

Overview

The before blocks defined in Minitest are inadequate for our use. This before_extension file allows us to use real before blocks.

Defined Under Namespace

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

Constant Summary collapse

VERSION_NUMBERS =
[
  VERSION_MAJOR = 3,
  VERSION_MINOR = 8,
  VERSION_BUILD = 0,
]
VERSION =
VERSION_NUMBERS.join(".")
NATURAL_ASSERTIONS_SUPPORTED =
begin
  require 'ripper'
  require 'sorcerer'
  true
rescue LoadError
  # Expected on Rubinius & old JRuby
  warn "    rspec-given: WARNING: Ripper is not available, so multi-line Then\n    statements will not be printed correctly and detailed failure\n    explanations of natural assertions WILL NOT be printed. Additionally,\n    assertions containing void statements (e.g. `Then { }`) will fail\n    in this runtime.\n  WARNING\n  false\nend\n".gsub(/^\s+/,'')
InvalidThenError =
Class.new(StandardError)

Class Method Summary collapse

Class Method Details

.count_assertion(*args) ⇒ Object

Increment the number of assertions made in the framework.



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

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)


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

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

.fail_with(*args) ⇒ Object

Fail an example with the given messages.



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

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

.frameworkObject



4
5
6
# File 'lib/given/module_methods.rb', line 4

def self.framework
  @_gvn_framework
end

.framework=(framework) ⇒ Object



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

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

.location_of(block) ⇒ Object

Return file and line number where the block is defined.



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

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

.natural_assertions_enabled?Boolean

TRUE if natural assertions are globally enabled?

Returns:

  • (Boolean)


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

def self.natural_assertions_enabled?
  @natural_assertions_enabled
end

.pending_errorObject

Error object used by the current framework to indicate a pending example.



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

def self.pending_error
  Given.framework.pending_error
end

.source_caching_disabledObject



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

def self.source_caching_disabled
  @_gvn_source_caching_disabled
end

.source_caching_disabled=(value) ⇒ Object



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

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

.start_evaluation(*args) ⇒ Object

Mark the start of a Then assertion evaluation.



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

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.



24
25
26
# File 'lib/given/module_methods.rb', line 24

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

.using_old_rspec?Boolean

Returns:

  • (Boolean)


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

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