Class: RspecStarter::Environment

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec_starter/environment.rb

Overview

Load the environment for RspecStarter.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args, &start_block) ⇒ Environment

&start_block is the start block from the host application’s bin/start_rspec file. It looks like this:

RspecStarter.start do
  command "something"
  task :task_one
  command "something"
  task :task two
  ... more commands and tasks...
end


15
16
17
18
19
20
21
22
23
# File 'lib/rspec_starter/environment.rb', line 15

def initialize(args, &start_block)
  @next_id = 0
  @step_info = {}

  load_step_info(&start_block)

  @options = Options.new(self, args, &start_block)
  # This will lazily load once execution starts.
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/rspec_starter/environment.rb', line 4

def options
  @options
end

Instance Method Details

#command(string, **args) ⇒ Object



33
34
35
36
# File 'lib/rspec_starter/environment.rb', line 33

def command(string, **args)
  step_id = next_id
  @step_info[step_id] = CommandContext.new(environment: self, id: step_id, command_string: string, requested_args: args)
end

#step_contextsObject



25
26
27
# File 'lib/rspec_starter/environment.rb', line 25

def step_contexts
  @step_info.values
end

#task(task_name, **args) ⇒ Object



38
39
40
41
42
# File 'lib/rspec_starter/environment.rb', line 38

def task(task_name, **args)
  step_id = next_id
  klass = RspecStarter.helpers.class_for_task_name(task_name)
  @step_info[step_id] = TaskContext.new(environment: self, id: step_id, step_class: klass, requested_args: args)
end

#unique_task_classesObject



29
30
31
# File 'lib/rspec_starter/environment.rb', line 29

def unique_task_classes
  @step_info.values.select(&:is_task?).collect(&:step_class).uniq
end