Class: Micronaut::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/micronaut/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/micronaut/configuration.rb', line 27

def initialize
  @backtrace_clean_patterns = [/\/lib\/ruby\//, /bin\/rcov:/, /vendor\/rails/, /bin\/micronaut/, /#{::Micronaut::InstallDirectory}/]
  @run_all_when_everything_filtered = true
  @trace = false
  @profile_examples = false
  @color_enabled = false
  @before_and_afters = { :before => { :each => [], :all => [] }, :after => { :each => [], :all => [] } }
  @include_or_extend_modules = []
  @formatter_to_use = Micronaut::Formatters::ProgressFormatter
  @filter = nil
end

Instance Attribute Details

#backtrace_clean_patternsObject (readonly)

Regex patterns to scrub backtrace with



5
6
7
# File 'lib/micronaut/configuration.rb', line 5

def backtrace_clean_patterns
  @backtrace_clean_patterns
end

#before_and_aftersObject (readonly)

All of the defined before/after blocks setup in the configuration



8
9
10
# File 'lib/micronaut/configuration.rb', line 8

def before_and_afters
  @before_and_afters
end

#filterObject (readonly)

Allows you to control what examples are ran by filtering



11
12
13
# File 'lib/micronaut/configuration.rb', line 11

def filter
  @filter
end

#include_or_extend_modulesObject (readonly)

Modules that will be included or extended based on given filters



14
15
16
# File 'lib/micronaut/configuration.rb', line 14

def include_or_extend_modules
  @include_or_extend_modules
end

#mock_frameworkObject (readonly)

Returns the value of attribute mock_framework.



25
26
27
# File 'lib/micronaut/configuration.rb', line 25

def mock_framework
  @mock_framework
end

#profile_examplesObject

Enable profiling of example run - defaults to false



20
21
22
# File 'lib/micronaut/configuration.rb', line 20

def profile_examples
  @profile_examples
end

#run_all_when_everything_filteredObject

Run all examples if the run is filtered, and no examples were found - defaults to true



17
18
19
# File 'lib/micronaut/configuration.rb', line 17

def run_all_when_everything_filtered
  @run_all_when_everything_filtered
end

#trace(override = false) ⇒ Object

Output some string for debugging/tracing assistance if trace is enabled The trace string should be sent as a block, which means it will only be interpolated if trace is actually enabled We allow an override here so that trace can be set at lower levels (such as the describe or example level)

Raises:

  • (ArgumentError)


23
24
25
# File 'lib/micronaut/configuration.rb', line 23

def trace
  @trace
end

Instance Method Details

#after(each_or_all = :each, options = {}, &block) ⇒ Object



139
140
141
# File 'lib/micronaut/configuration.rb', line 139

def after(each_or_all=:each, options={}, &block)
  before_and_afters[:after][each_or_all] << [options, block]
end

#alias_example_to(new_name, extra_options = {}) ⇒ Object

E.g. alias_example_to :crazy_slow, :speed => ‘crazy_slow’ defines crazy_slow as an example variant that has the crazy_slow speed option



41
42
43
# File 'lib/micronaut/configuration.rb', line 41

def alias_example_to(new_name, extra_options={})
  Micronaut::Behaviour.alias_example_to(new_name, extra_options)
end

#autorun!Object



66
67
68
# File 'lib/micronaut/configuration.rb', line 66

def autorun!
  Micronaut::Runner.autorun
end

#before(each_or_all = :each, options = {}, &block) ⇒ Object



135
136
137
# File 'lib/micronaut/configuration.rb', line 135

def before(each_or_all=:each, options={}, &block)
  before_and_afters[:before][each_or_all] << [options, block]
end

#cleaned_from_backtrace?(line) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/micronaut/configuration.rb', line 45

def cleaned_from_backtrace?(line)
  @backtrace_clean_patterns.any? { |regex| line =~ regex }
end

#color_enabled=(on_or_off) ⇒ Object



70
71
72
# File 'lib/micronaut/configuration.rb', line 70

def color_enabled=(on_or_off)
  @color_enabled = on_or_off
end

#color_enabled?Boolean

Output with ANSI color enabled? Defaults to false

Returns:

  • (Boolean)


75
76
77
# File 'lib/micronaut/configuration.rb', line 75

def color_enabled?
  @color_enabled
end

#extend(mod, options = {}) ⇒ Object



123
124
125
# File 'lib/micronaut/configuration.rb', line 123

def extend(mod, options={})
  include_or_extend_modules << [:extend, mod, options]
end

#filter_run(options = {}) ⇒ Object



79
80
81
# File 'lib/micronaut/configuration.rb', line 79

def filter_run(options={})
  @filter = options
end

#find_before_or_after(desired_type, desired_each_or_all, group) ⇒ Object



143
144
145
146
147
148
149
# File 'lib/micronaut/configuration.rb', line 143

def find_before_or_after(desired_type, desired_each_or_all, group)
  before_and_afters[desired_type][desired_each_or_all].select do |options, block|
    options.all? do |filter_on, filter|
      Micronaut.world.apply_condition(filter_on, filter, group.)
    end
  end.map { |options, block| block }
end

#find_modules(group) ⇒ Object



127
128
129
130
131
132
133
# File 'lib/micronaut/configuration.rb', line 127

def find_modules(group)
  include_or_extend_modules.select do |include_or_extend, mod, options|
    options.all? do |filter_on, filter|
      Micronaut.world.apply_condition(filter_on, filter, group.)
    end
  end
end

#formatterObject

The formatter all output should use. Defaults to the progress formatter



95
96
97
# File 'lib/micronaut/configuration.rb', line 95

def formatter
  @formatter ||= @formatter_to_use.new
end

#formatter=(formatter_to_use) ⇒ Object



87
88
89
90
91
92
# File 'lib/micronaut/configuration.rb', line 87

def formatter=(formatter_to_use)
  @formatter_to_use = case formatter_to_use.to_s
                      when 'documentation' then Micronaut::Formatters::DocumentationFormatter
                      when 'progress' then Micronaut::Formatters::ProgressFormatter
                      end
end

#include(mod, options = {}) ⇒ Object



119
120
121
# File 'lib/micronaut/configuration.rb', line 119

def include(mod, options={})
  include_or_extend_modules << [:include, mod, options]
end

#mock_with(make_a_mockery_with = nil) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/micronaut/configuration.rb', line 49

def mock_with(make_a_mockery_with=nil)
  @mock_framework = make_a_mockery_with
  mock_framework_class = case make_a_mockery_with.to_s
                         when /mocha/i
                           require 'micronaut/mocking/with_mocha'
                           Micronaut::Mocking::WithMocha
                         when /rr/i
                           require 'micronaut/mocking/with_rr'
                           Micronaut::Mocking::WithRR
                         else
                           require 'micronaut/mocking/with_absolutely_nothing'
                           Micronaut::Mocking::WithAbsolutelyNothing
                         end 

  Micronaut::Behaviour.send(:include, mock_framework_class)
end

#outputObject

Where does output go? For now $stdout



100
101
102
# File 'lib/micronaut/configuration.rb', line 100

def output
  $stdout
end

#run_all_when_everything_filtered?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/micronaut/configuration.rb', line 83

def run_all_when_everything_filtered?
  @run_all_when_everything_filtered
end

#trace?Boolean

If true, Micronaut will provide detailed trace output of its self as it runs. Can be turned on at the global (configuration) level or at the individual behaviour (describe) level.

Returns:

  • (Boolean)


115
116
117
# File 'lib/micronaut/configuration.rb', line 115

def trace?
  @trace == true
end