Class: Loupe::Test

Inherits:
Object
  • Object
show all
Defined in:
lib/loupe/test.rb

Overview

Test

The parent class for tests. Tests should inherit from this class in order to be run.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(reporter, method_name, options = {}) ⇒ Loupe::Test

Parameters:

  • reporter (Loupe::Reporter)
  • method_name (Symbol)
  • options (Hash<Symbol, BasicObject>) (defaults to: {})


111
112
113
114
115
116
117
# File 'lib/loupe/test.rb', line 111

def initialize(reporter, method_name, options = {})
  @reporter = reporter
  @color = Color.new(options[:color])
  @name = method_name
  @method = method(method_name)
  @file, @line_number = @method.source_location
end

Instance Attribute Details

#colorLoupe::Color (readonly)

Returns:



65
66
67
# File 'lib/loupe/test.rb', line 65

def color
  @color
end

#fileString (readonly)

Returns:

  • (String)


62
63
64
# File 'lib/loupe/test.rb', line 62

def file
  @file
end

#line_numberInteger (readonly)

Returns:

  • (Integer)


59
60
61
# File 'lib/loupe/test.rb', line 59

def line_number
  @line_number
end

#nameString (readonly)

Returns:

  • (String)


68
69
70
# File 'lib/loupe/test.rb', line 68

def name
  @name
end

#reporterLoupe::Reporter (readonly)

Returns:



56
57
58
# File 'lib/loupe/test.rb', line 56

def reporter
  @reporter
end

Class Method Details

.add_line_number(number) ⇒ void

This method returns an undefined value.

Parameters:

  • number (Integer)


77
78
79
# File 'lib/loupe/test.rb', line 77

def self.add_line_number(number)
  classes[@current_class] << number
end

.classesHash<Class, Array<Integer>>

Returns:

  • (Hash<Class, Array<Integer>>)


71
72
73
# File 'lib/loupe/test.rb', line 71

def self.classes
  @classes ||= {}
end

.inherited(test_class) ⇒ void

This method returns an undefined value.

Parameters:

  • test_class (Class)


83
84
85
86
87
# File 'lib/loupe/test.rb', line 83

def self.inherited(test_class)
  @current_class = test_class
  classes[test_class] = []
  super
end

.run(method_name, options = {}) ⇒ Loupe::Reporter

Run a single test with designated by ‘method_name`

Parameters:

  • method_name (Symbol)
  • options (Hash<Symbol, BasicObject>) (defaults to: {})

Returns:



99
100
101
102
103
104
105
# File 'lib/loupe/test.rb', line 99

def self.run(method_name, options = {})
  reporter = options[:interactive] ? PagedReporter.new(options) : PlainReporter.new(options)
  new(reporter, method_name, options).run
  reporter
rescue Expectation::ExpectationFailed
  reporter
end

.test_listArray<Symbol>

Returns:

  • (Array<Symbol>)


90
91
92
# File 'lib/loupe/test.rb', line 90

def self.test_list
  instance_methods(false).grep(/^test.*/)
end

Instance Method Details

#aftervoid

This method returns an undefined value.



134
# File 'lib/loupe/test.rb', line 134

def after; end

#beforevoid

This method returns an undefined value.



131
# File 'lib/loupe/test.rb', line 131

def before; end

#runvoid

This method returns an undefined value.

Run the instantiated test, which corresponds to a single method.



122
123
124
125
126
127
128
# File 'lib/loupe/test.rb', line 122

def run
  @reporter.increment_test_count
  before
  @method.call
  after
  @reporter.increment_success_count
end