Class: Spinach::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/spinach/config.rb

Overview

The config object holds all the runtime configurations needed for spinach to run.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#audittrue/false

“audit” enables step auditing mode

Returns:

  • (true/false)

    The audit flag.



153
154
155
# File 'lib/spinach/config.rb', line 153

def audit
  @audit || false
end

#config_pathString

It allows you to set a config file to parse for all the other options to be set

Returns:

  • (String)

    The config file name



162
163
164
# File 'lib/spinach/config.rb', line 162

def config_path
  @config_path ||= 'config/spinach.yml'
end

#default_reporter=(value) ⇒ Object (writeonly)

Sets the attribute default_reporter

Parameters:

  • value

    the value to set the attribute default_reporter to.



25
26
27
# File 'lib/spinach/config.rb', line 25

def default_reporter=(value)
  @default_reporter = value
end

#fail_fasttrue/false

The “fail_fast” determines if the suite run should exit when encountering a failure/error

Returns:

  • (true/false)

    The fail_fast flag.



143
144
145
# File 'lib/spinach/config.rb', line 143

def fail_fast
  @fail_fast
end

#failure_exceptionsArray<Exception>

The failure exceptions return an array of exceptions to be captured and considered as failures (as opposite of errors)

Returns:

  • (Array<Exception>)


132
133
134
# File 'lib/spinach/config.rb', line 132

def failure_exceptions
  @failure_exceptions ||= []
end

#features_pathString

The “features path” holds the place where your features will be searched for. Defaults to 'features'

Returns:

  • (String)

    The features path.



47
48
49
# File 'lib/spinach/config.rb', line 47

def features_path
  @features_path || 'features'
end

#generateObject



91
92
93
# File 'lib/spinach/config.rb', line 91

def generate
  @generate || false
end

#reporter_classesArray<reporter object>

The “reporter classes” holds an array of reporter class name Default to [“Spinach::Reporter::Stdout”]

Returns:

  • (Array<reporter object>)

    The reporters that respond to specific messages.



58
59
60
# File 'lib/spinach/config.rb', line 58

def reporter_classes
  @reporter_classes || ["Spinach::Reporter::Stdout"]
end

#reporter_optionsObject

The “reporter_options” holds the options passed to reporter_classes



65
66
67
# File 'lib/spinach/config.rb', line 65

def reporter_options
  @reporter_options || {}
end

#save_and_open_page_on_failureObject

When using capybara, it automatically shows the current page when there's a failure



169
170
171
# File 'lib/spinach/config.rb', line 169

def save_and_open_page_on_failure
  @save_and_open_page_on_failure ||= false
end

#step_definitions_pathString

The “step definitions path” holds the place where your feature step classes will be searched for. Defaults to '##features_path/steps'

Returns:

  • (String)

    The step definitions path.



76
77
78
# File 'lib/spinach/config.rb', line 76

def step_definitions_path
  @step_definitions_path || "#{self.features_path}/steps"
end

#support_pathString

The “support path” helds the place where you can put your configuration files. Defaults to '##features_path/support'

Returns:

  • (String)

    The support file path.



87
88
89
# File 'lib/spinach/config.rb', line 87

def support_path
  @support_path || "#{self.features_path}/support"
end

#tagsArray

Tags to tell Spinach that you only want to run scenarios that have (or don't have) certain tags.

Returns:

  • (Array)

    The tags.



179
180
181
# File 'lib/spinach/config.rb', line 179

def tags
  @tags ||= []
end

Instance Method Details

#[](attribute) ⇒ Object

Allows you to read the config object using a hash-like syntax.

Examples:

Spinach.config[:step_definitions_path]
# => 'features/steps'

Parameters:

  • attribute (String)

    The attribute to fetch.



105
106
107
# File 'lib/spinach/config.rb', line 105

def [](attribute)
  self.send(attribute)
end

#[]=(attribute, value) ⇒ Object

Allows you to set config properties using a hash-like syntax.

Examples:

Spinach.config[:step_definitions_path] = 'integration/steps'
  # => 'integration/steps'

Parameters:

  • attribute (#to_s)

    The attribute to set.

  • value (Object)

    The value to set the attribute to.



122
123
124
# File 'lib/spinach/config.rb', line 122

def []=(attribute, value)
  self.send("#{attribute}=", value)
end

#parse_from_fileBoolean

Parse options from the config file

Returns:

  • (Boolean)

    If the config was parsed from the file



188
189
190
191
192
193
194
195
# File 'lib/spinach/config.rb', line 188

def parse_from_file
  parsed_opts = YAML.load_file(config_path)
  parsed_opts.delete_if{|k| k.to_s == 'config_path'}
  parsed_opts.each_pair{|k,v| self[k] = v}
  true
rescue Errno::ENOENT
  false
end