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.



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/micronaut/configuration.rb', line 30

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, @exclusion_filter = nil, nil
  mock_with nil unless @mock_framework_established
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

#exclusion_filterObject (readonly)

Returns the value of attribute exclusion_filter.



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

def exclusion_filter
  @exclusion_filter
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



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

def include_or_extend_modules
  @include_or_extend_modules
end

#mock_frameworkObject (readonly)

Returns the value of attribute mock_framework.



28
29
30
# File 'lib/micronaut/configuration.rb', line 28

def mock_framework
  @mock_framework
end

#profile_examplesObject

Enable profiling of example run - defaults to false



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

def profile_examples
  @profile_examples
end

#run_all_when_everything_filteredObject

Run all examples if the run is filtered, and no examples were found. Normally this is what you want - when using focused examples for instance. Defaults to true



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

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)


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

def trace
  @trace
end

Instance Method Details

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



150
151
152
# File 'lib/micronaut/configuration.rb', line 150

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



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

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

#autorun!Object



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

def autorun!
  Micronaut::Runner.autorun
end

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



146
147
148
# File 'lib/micronaut/configuration.rb', line 146

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)


49
50
51
# File 'lib/micronaut/configuration.rb', line 49

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

#color_enabled=(on_or_off) ⇒ Object

Turn ANSI on with ‘true’, or off with ‘false’



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

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)


81
82
83
# File 'lib/micronaut/configuration.rb', line 81

def color_enabled?
  @color_enabled
end

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



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

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

#filter_run(options = {}) ⇒ Object



85
86
87
# File 'lib/micronaut/configuration.rb', line 85

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

#find_before_or_after(desired_before_or_after, desired_each_or_all, group) ⇒ Object



154
155
156
157
158
159
160
# File 'lib/micronaut/configuration.rb', line 154

def find_before_or_after(desired_before_or_after, desired_each_or_all, group)
  before_and_afters[desired_before_or_after][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



138
139
140
141
142
143
144
# File 'lib/micronaut/configuration.rb', line 138

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



102
103
104
# File 'lib/micronaut/configuration.rb', line 102

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

#formatter=(formatter_to_use) ⇒ Object



93
94
95
96
97
98
99
# File 'lib/micronaut/configuration.rb', line 93

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
                      else raise(ArgumentError, "Formatter '#{formatter_to_use}' unknown - maybe you meant 'documentation' or 'progress'?.")
                      end
end

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



130
131
132
# File 'lib/micronaut/configuration.rb', line 130

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

#mock_with(make_a_mockery_with = nil) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/micronaut/configuration.rb', line 53

def mock_with(make_a_mockery_with=nil)
  @mock_framework_established = true
  @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



107
108
109
# File 'lib/micronaut/configuration.rb', line 107

def output
  $stdout
end

#puts(msg) ⇒ Object



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

def puts(msg)
  output.puts(msg)    
end

#run_all_when_everything_filtered?Boolean

Returns:

  • (Boolean)


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

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)


126
127
128
# File 'lib/micronaut/configuration.rb', line 126

def trace?
  @trace == true
end