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',
    user: 'SWAT_USER_NAME',
})

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of CommandsBuilder.



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

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



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

def current_branch
  call_command(current_branch_command) rescue 'undefined'
end

.current_revision_nameObject



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

def current_revision_name
  env[ENV_VARS.revision_name]
end

.current_revision_timeObject



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

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

.current_scenariosObject



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

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

.current_thread_idObject



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

def current_thread_id
  env[ENV_VARS.thread_id].to_i
end

.current_thread_nameObject



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

def current_thread_name
  env[ENV_VARS.thread_name]
end

.current_threads_countObject



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

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

.current_userObject



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

def current_user
  (env[ENV_VARS.user] || call_command(current_user_command)) rescue 'undefined'
end

.debug_mode?Boolean

Returns:

  • (Boolean)


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

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

.envObject



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

def env
  ENV
end

.nowObject



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

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

Instance Method Details

#envObject



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

def env
  self.class.env
end

#thread_name(thread_opts, index) ⇒ Object



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

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

#thread_scenario(thread_opts, index) ⇒ Object



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

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



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

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

#threads_countObject



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

def threads_count
  @config[:threads].count
end