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.



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

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
  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

#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.



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

def mock_framework
  @mock_framework
end

#profile_examplesObject

Enable profiling of example run - defaults to false



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

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



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

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)


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

def trace
  @trace
end

Instance Method Details

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



148
149
150
# File 'lib/micronaut/configuration.rb', line 148

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



43
44
45
# File 'lib/micronaut/configuration.rb', line 43

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

#autorun!Object



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

def autorun!
  Micronaut::Runner.autorun
end

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



144
145
146
# File 'lib/micronaut/configuration.rb', line 144

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)


47
48
49
# File 'lib/micronaut/configuration.rb', line 47

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’



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

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)


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

def color_enabled?
  @color_enabled
end

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



132
133
134
# File 'lib/micronaut/configuration.rb', line 132

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

#filter_run(options = {}) ⇒ Object



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

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

#find_before_or_after(desired_before_or_after, desired_each_or_all, group) ⇒ Object



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

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



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

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



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

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

#formatter=(formatter_to_use) ⇒ Object



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

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



128
129
130
# File 'lib/micronaut/configuration.rb', line 128

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

#mock_with(make_a_mockery_with = nil) ⇒ Object



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

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



105
106
107
# File 'lib/micronaut/configuration.rb', line 105

def output
  $stdout
end

#puts(msg) ⇒ Object



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

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

#run_all_when_everything_filtered?Boolean

Returns:

  • (Boolean)


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

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)


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

def trace?
  @trace == true
end