Class: RspecAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/shared/adapters/rspec_adapter.rb

Class Method Summary collapse

Class Method Details

.base_pathObject



32
33
34
# File 'lib/shared/adapters/rspec_adapter.rb', line 32

def self.base_path
  type
end

.command(project_path, ruby_interpreter, files) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/shared/adapters/rspec_adapter.rb', line 6

def self.command(project_path, ruby_interpreter, files)
  spec_command = RubyEnv.ruby_command(project_path, :script => "script/spec", :bin => "rspec",
                                                    :ruby_interpreter => ruby_interpreter)
  if File.exists?("#{project_path}/spec/spec.opts")
    spec_command += " -O spec/spec.opts"
  end

  "export RSPEC_COLOR=true; #{spec_command} #{files}"
end

.get_sizes(files) ⇒ Object



20
21
22
# File 'lib/shared/adapters/rspec_adapter.rb', line 20

def self.get_sizes(files)
  files.map { |file| File.stat(file).size }
end

.nameObject



36
37
38
# File 'lib/shared/adapters/rspec_adapter.rb', line 36

def self.name
  'RSpec'
end

.pluralizedObject



28
29
30
# File 'lib/shared/adapters/rspec_adapter.rb', line 28

def self.pluralized
  'specs'
end

.requester_portObject



24
25
26
# File 'lib/shared/adapters/rspec_adapter.rb', line 24

def self.requester_port
  2299
end

.sum_results(results) ⇒ Object

This is an optional method. It gets passed the entire test result and summarizes it. See the tests.



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/shared/adapters/rspec_adapter.rb', line 45

def self.sum_results(results)
  examples, failures, pending = 0, 0, 0
  results.split("\n").each do |line|
    line =~ /(\d+) examples?, (\d+) failures?(, (\d+) pending)?/
    next unless $1
    examples += $1.to_i
    failures += $2.to_i
    pending += $4.to_i
  end

  result = [ pluralize(examples, 'example'), pluralize(failures, 'failure'), (pending > 0 ? "#{pending} pending" : nil) ].compact.join(', ')
  if failures == 0 && pending == 0
    Color.colorize(result, :green)
  elsif failures == 0 && pending > 0
    Color.colorize(result, :orange)
  else
    Color.colorize(result, :red)
  end
end

.test_files(dir) ⇒ Object



16
17
18
# File 'lib/shared/adapters/rspec_adapter.rb', line 16

def self.test_files(dir)
  Dir["#{dir}/#{file_pattern}"]
end

.typeObject



40
41
42
# File 'lib/shared/adapters/rspec_adapter.rb', line 40

def self.type
  'spec'
end