Class: Swat::UI::RSpecCommands::CommandsBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/swat/ui/rspec_commands.rb

Constant Summary collapse

ENV_VARS =
OpenStruct.new({
    rails_env: 'RAILS_ENV',
    db_env_number: 'TEST_ENV_NUMBER',

    time: 'SWAT_CURRENT_REVISION',
    threads_count: 'SWAT_THREADS_COUNT',
    thread_id: 'SWAT_CURRENT_THREAD_ID',
    thread_name: 'SWAT_CURRENT_THREAD_NAME',
    branch: 'SWAT_CURRENT_BRANCH_NAME',
    revision_name: 'SWAT_CURRENT_REVISION_NAME',
    revision_time: 'SWAT_CURRENT_REVISION_TIME',

    debug_mode: 'SWAT_DBG',
})

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(conf_options, time, name = nil) ⇒ CommandsBuilder



24
25
26
27
28
29
30
31
# File 'lib/swat/ui/rspec_commands.rb', line 24

def initialize(conf_options, time, name=nil)
  @config = conf_options
  unless @config[:threads]
    @config[:threads] = [{ name: 'Full' }]
  end
  @time = time
  @name = name || @time
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



8
9
10
# File 'lib/swat/ui/rspec_commands.rb', line 8

def config
  @config
end

#revision_nameObject (readonly)

Returns the value of attribute revision_name.



8
9
10
# File 'lib/swat/ui/rspec_commands.rb', line 8

def revision_name
  @revision_name
end

#timeObject (readonly)

Returns the value of attribute time.



8
9
10
# File 'lib/swat/ui/rspec_commands.rb', line 8

def time
  @time
end

Class Method Details

.current_branchObject



93
94
95
# File 'lib/swat/ui/rspec_commands.rb', line 93

def current_branch
  call_command(current_branch_command)
end

.current_revision_nameObject



77
78
79
# File 'lib/swat/ui/rspec_commands.rb', line 77

def current_revision_name
  env[ENV_VARS.revision_name]
end

.current_revision_timeObject



61
62
63
# File 'lib/swat/ui/rspec_commands.rb', line 61

def current_revision_time
  env[ENV_VARS.revision_time] ? env[ENV_VARS.revision_time].to_i : now.to_i
end

.current_scenariosObject



81
82
83
# File 'lib/swat/ui/rspec_commands.rb', line 81

def current_scenarios
  new(Swat::UI.config.options, current_revision_time, current_revision_name).thread_scenarios
end

.current_thread_idObject



73
74
75
# File 'lib/swat/ui/rspec_commands.rb', line 73

def current_thread_id
  env[ENV_VARS.thread_id].to_i
end

.current_thread_nameObject



69
70
71
# File 'lib/swat/ui/rspec_commands.rb', line 69

def current_thread_name
  env[ENV_VARS.thread_name]
end

.current_threads_countObject



65
66
67
# File 'lib/swat/ui/rspec_commands.rb', line 65

def current_threads_count
  env[ENV_VARS.threads_count] || 1
end

.current_userObject



97
98
99
# File 'lib/swat/ui/rspec_commands.rb', line 97

def current_user
  call_command(current_user_command)
end

.debug_mode?Boolean



89
90
91
# File 'lib/swat/ui/rspec_commands.rb', line 89

def debug_mode?
  !!env[ENV_VARS.debug_mode]
end

.envObject



101
102
103
# File 'lib/swat/ui/rspec_commands.rb', line 101

def env
  ENV
end

.nowObject



85
86
87
# File 'lib/swat/ui/rspec_commands.rb', line 85

def now
  (Time.respond_to?(:now_without_mock_time) ? Time.now_without_mock_time : Time.now)
end

Instance Method Details

#envObject



121
122
123
# File 'lib/swat/ui/rspec_commands.rb', line 121

def env
  self.class.env
end

#thread_name(thread_opts, index) ⇒ Object



56
57
58
# File 'lib/swat/ui/rspec_commands.rb', line 56

def thread_name(thread_opts, index)
  (thread_opts[:name] || "Thread##{index+1}")
end

#thread_scenario(thread_opts, index) ⇒ Object



45
46
47
48
49
50
51
52
53
54
# File 'lib/swat/ui/rspec_commands.rb', line 45

def thread_scenario(thread_opts, index)
  {
      index: index,
      name: @name,
      thread: thread_name(thread_opts, index),
      clean: clean_command(thread_opts, index),
      prepare: prepare_command(thread_opts, index),
      run: run_command(thread_opts, index),
  }
end

#thread_scenariosObject



37
38
39
40
41
42
43
# File 'lib/swat/ui/rspec_commands.rb', line 37

def thread_scenarios
  res = []
  @config[:threads].each_with_index  do |th, index|
    res << thread_scenario(th, index)
  end
  res
end

#threads_countObject



33
34
35
# File 'lib/swat/ui/rspec_commands.rb', line 33

def threads_count
  @config[:threads].count
end