Class: InfinityTest::TestFramework

Inherits:
Object
  • Object
show all
Includes:
BinaryPath, Builder, Environment
Defined in:
lib/infinity_test/test_framework.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Builder

#construct_command, #construct_commands, #resolve_options, #run_with_bundler!, #run_without_bundler!

Methods included from Environment

#environments

Methods included from BinaryPath

#have_binary?, included, #print_message, #rvm_bin_path, #search_binary

Constructor Details

#initialize(options = {}) ⇒ TestFramework

Returns a new instance of TestFramework.



11
12
13
14
15
# File 'lib/infinity_test/test_framework.rb', line 11

def initialize(options={})
  @application = InfinityTest.application
  @rubies = options[:rubies] || []
  @specific_options = options[:specific_options] || {}
end

Instance Attribute Details

#applicationObject

Returns the value of attribute application.



9
10
11
# File 'lib/infinity_test/test_framework.rb', line 9

def application
  @application
end

#messageObject

Returns the value of attribute message.



9
10
11
# File 'lib/infinity_test/test_framework.rb', line 9

def message
  @message
end

#rubiesObject

Returns the value of attribute rubies.



9
10
11
# File 'lib/infinity_test/test_framework.rb', line 9

def rubies
  @rubies
end

#specific_optionsObject

Returns the value of attribute specific_options.



9
10
11
# File 'lib/infinity_test/test_framework.rb', line 9

def specific_options
  @specific_options
end

#test_patternObject

Returns the value of attribute test_pattern.



9
10
11
# File 'lib/infinity_test/test_framework.rb', line 9

def test_pattern
  @test_pattern
end

Class Method Details

.create_accessors(hash) ⇒ Object

Create accessors for keys of the Hash passed in argument

create_accessors({ :example => ‘…’, :failure => ‘…’}) # => attr_accessor :example, :failure



62
63
64
65
66
# File 'lib/infinity_test/test_framework.rb', line 62

def self.create_accessors(hash)
  hash.keys.each do |attribute|
    attr_accessor attribute
  end
end

.parse_results(patterns) ⇒ Object

Method used in the subclasses of TestFramework

Example:

class Rspec < TestFramework
  parse_results :example => /(\d+) example/, :failure => /(\d+) failure/, :pending => /(\d+) pending/
end

Then will create @examples, @failure and @pending instance variables with the values in the test result

Or with Test::Unit:

class TestUnit < TestFramework
  parse_results :tests => /(\d+) tests/, :assertions => /(\d+) assertions/, :failures => /(\d+) failures/, :errors => /(\d+) errors/
end

Then will create @tests, @assertions, @failures and @errors instance variables with the values in the test result

Raises:

  • (ArgumentError)


50
51
52
53
54
55
56
# File 'lib/infinity_test/test_framework.rb', line 50

def self.parse_results(patterns)
  raise(ArgumentError, 'patterns should not be empty') if patterns.empty?
  create_accessors(patterns)
  define_method(:parse_results) do |results|
    set_instances(:shell_result => test_message(results, patterns), :patterns => patterns)
  end
end

Instance Method Details

#all_filesObject

Return all the files match by test_pattern



19
20
21
# File 'lib/infinity_test/test_framework.rb', line 19

def all_files
  Dir[@test_pattern].sort
end

#create_pattern_instance_variables(patterns, shell_result) ⇒ Object

Create the instance pass in the patterns options

Useful for the parse results:

parse_results :tests => /.../, :assertions => /.../

Then will create @tests ans @assertions (the keys of the Hash)



75
76
77
78
79
80
81
# File 'lib/infinity_test/test_framework.rb', line 75

def create_pattern_instance_variables(patterns, shell_result)
  patterns.each do |key, pattern|
    number = shell_result[pattern, 1].to_i
    instance_variable_set("@#{key}", number)
  end
  @message = shell_result.gsub(/\e\[\d+?m/, '') # Clean ANSIColor strings
end

#decide_files(file) ⇒ Object



27
28
29
30
# File 'lib/infinity_test/test_framework.rb', line 27

def decide_files(file)
  return file if file
  test_files
end

#test_filesObject



23
24
25
# File 'lib/infinity_test/test_framework.rb', line 23

def test_files
  all_files.collect { |file| file }.join(' ')
end

#test_message(output, patterns) ⇒ Object

Return the message of the tests

test_message(‘0 examples, 0 failures’, { :example => /(d) example/}) # => ‘0 examples, 0 failures’ test_message(‘.…n4 examples, 0 failures’, { :examples => /(d) examples/}) # => ‘4 examples, 0 failures’



88
89
90
91
92
93
94
95
# File 'lib/infinity_test/test_framework.rb', line 88

def test_message(output, patterns)
  lines = output.split("\n")
  final_result = []
  patterns.each do |key, pattern|
    final_result << lines.select { |line| line =~ pattern }
  end
  final_result.flatten.last
end