Module: EffectiveTestBot

Defined in:
lib/effective_test_bot.rb,
lib/effective_test_bot/engine.rb,
lib/effective_test_bot/version.rb,
lib/generators/effective_test_bot/install_generator.rb

Defined Under Namespace

Modules: Generators Classes: Engine

Constant Summary collapse

VERSION =
'0.4.4'.freeze

Class Method Summary collapse

Class Method Details

.autosave_animated_gif_on_failure? ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/effective_test_bot.rb', line 49

def self.autosave_animated_gif_on_failure?
  screenshots && autosave_animated_gif_on_failure
end

.excepts ⇒ Object



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

def self.excepts
  @@excepts ||= flatten_and_sort(except)
end

.flatten_and_sort(skips) ⇒ Object

We need to flatten any Hashes into 'users#create_invalid' => ['assert_path', 'assert_page_title'], into this ['users#create_invalid assert_path' 'users#create_invalid assert_page_title']



101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/effective_test_bot.rb', line 101

def self.flatten_and_sort(skips)
  Array(skips).flat_map do |skip|
    case skip
    when Symbol
      skip.to_s
    when Hash
      skip.keys.product(skip.values.flatten).map { |p| p.join(' ') }
    else
      skip
    end
  end.compact.sort
end

.onlies ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/effective_test_bot.rb', line 71

def self.onlies
  @@onlines ||= begin
    flatten_and_sort(
      if ENV['TEST_BOT_TEST'].present?
        ENV['TEST_BOT_TEST'].to_s.gsub('[', '').gsub(']', '').split(',').map { |str| str.strip }
      else
        only
      end
    )
  end
end

.screenshots? ⇒ Boolean

If you call rake test:bot TOUR=false, then disable screenshots too

Returns:

  • (Boolean)


45
46
47
# File 'lib/effective_test_bot.rb', line 45

def self.screenshots?
  screenshots == true
end

.setup {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



11
12
13
# File 'lib/effective_test_bot.rb', line 11

def self.setup
  yield self
end

.skip?(test, assertion = nil) ⇒ Boolean

Test could be something like "crud_test", "crud_test (documents#new)", "documents", documents#new" Assertion will be page_title, or flash

Returns:

  • (Boolean)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/effective_test_bot.rb', line 18

def self.skip?(test, assertion = nil)
  return false if (test || assertion).blank?

  test = test.to_s
  assertion = assertion.to_s

  # If I get passed a method_name, "crud_test: (posts#create_invalid)" extract the inner test name from it
  # I dunno why this is needed really, but it might help someone one day.
  if test.include?('_test: (')  # This is how the BaseDsl test_bot_method_name formats the test names.
    left = test.index('(') || -1
    right = test.rindex(')') || (test.length+1)
    test = test[(left+1)..(right-1)]
  end

  value = "#{test} #{assertion}".strip # This is the format config.excepts is flattened into

  # Excepts are defined in the app's config/initializers/effective_test_bot.rb file
  return true if excepts.any? { |except| [test, assertion, value].include?(except) }

  # Onlies are defined in the same config file, or on the command like rake test:bot TEST=posts#new
  # It doesn't match just 'flash' or 'page_title' assertions
  return true if onlies.present? && onlies.find { |only| test.start_with?(only) }.blank?

  false # Don't skip this test
end

.tour_mode? ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
56
57
58
59
# File 'lib/effective_test_bot.rb', line 53

def self.tour_mode?
  if ENV['TOUR'].present?
    ['true', 'verbose', 'debug'].include?(ENV['TOUR'].to_s.downcase)
  else
    screenshots && (tour_mode != false)
  end
end

.tour_mode_verbose? ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
64
65
66
67
# File 'lib/effective_test_bot.rb', line 61

def self.tour_mode_verbose?
  if ENV['TOUR'].present?
    ['verbose', 'debug'].include?(ENV['TOUR'].to_s.downcase)
  else
    screenshots && ['verbose', 'debug'].include?(tour_mode.to_s)
  end
end