Module: Test::This

Defined in:
lib/test/this.rb,
lib/test/this/version.rb

Constant Summary collapse

VERSION =
'0.2.0'

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.file_suffixObject



32
33
34
# File 'lib/test/this.rb', line 32

def self.file_suffix
  @file_suffix ||= '_test.rb'
end

.test_method_prefixObject



36
37
38
# File 'lib/test/this.rb', line 36

def self.test_method_prefix
  @test_method_prefix ||= 'test_'
end

.test_pathObject



40
41
42
# File 'lib/test/this.rb', line 40

def self.test_path
  @test_path ||= File.join(Dir.pwd, 'test')
end

Instance Attribute Details

#file_suffixString

Test files are typically suffixed with either ‘_test.rb` or `_spec.rb`. This attribute allows you to specify what file suffix your tests use.

Returns:

  • (String)

    A file suffix - defaults to “_test.rb”.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/test/this.rb', line 23

module This
  autoload :VERSION, 'test/this/version'

  class << self
    attr_writer :file_suffix, :test_method_prefix, :test_path

    alias_method :configure, :tap
  end

  def self.file_suffix
    @file_suffix ||= '_test.rb'
  end

  def self.test_method_prefix
    @test_method_prefix ||= 'test_'
  end

  def self.test_path
    @test_path ||= File.join(Dir.pwd, 'test')
  end

  def self.execute(path, name=nil)
    path = get_test_path(path)

    command = %Q[ruby -I"lib:test" #{path}]
    command << " -n #{get_test_name(name)}" unless name.nil?

    system command
  end

  def self.get_test_path(path)
    File.join(test_path, "#{path}#{file_suffix}")
  end

  def self.get_test_name(name)
    "#{test_method_prefix}#{name.gsub(' ', '_')}"
  end
end

#test_method_prefixString

Minitest methods are prefixed with ‘test_`. The Rails `test` method generates tests for Minitest that have the same prefix. This might not apply to all test suites, so it can be configured when necessary.

Returns:

  • (String)

    Prefix for test methods.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/test/this.rb', line 23

module This
  autoload :VERSION, 'test/this/version'

  class << self
    attr_writer :file_suffix, :test_method_prefix, :test_path

    alias_method :configure, :tap
  end

  def self.file_suffix
    @file_suffix ||= '_test.rb'
  end

  def self.test_method_prefix
    @test_method_prefix ||= 'test_'
  end

  def self.test_path
    @test_path ||= File.join(Dir.pwd, 'test')
  end

  def self.execute(path, name=nil)
    path = get_test_path(path)

    command = %Q[ruby -I"lib:test" #{path}]
    command << " -n #{get_test_name(name)}" unless name.nil?

    system command
  end

  def self.get_test_path(path)
    File.join(test_path, "#{path}#{file_suffix}")
  end

  def self.get_test_name(name)
    "#{test_method_prefix}#{name.gsub(' ', '_')}"
  end
end

#test_pathString

The full path to the root of the tests. This defaults to using the current directory that the task was called from.

Returns:

  • (String)

    Full path to the tests.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/test/this.rb', line 23

module This
  autoload :VERSION, 'test/this/version'

  class << self
    attr_writer :file_suffix, :test_method_prefix, :test_path

    alias_method :configure, :tap
  end

  def self.file_suffix
    @file_suffix ||= '_test.rb'
  end

  def self.test_method_prefix
    @test_method_prefix ||= 'test_'
  end

  def self.test_path
    @test_path ||= File.join(Dir.pwd, 'test')
  end

  def self.execute(path, name=nil)
    path = get_test_path(path)

    command = %Q[ruby -I"lib:test" #{path}]
    command << " -n #{get_test_name(name)}" unless name.nil?

    system command
  end

  def self.get_test_path(path)
    File.join(test_path, "#{path}#{file_suffix}")
  end

  def self.get_test_name(name)
    "#{test_method_prefix}#{name.gsub(' ', '_')}"
  end
end

Class Method Details

.execute(path, name = nil) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/test/this.rb', line 44

def self.execute(path, name=nil)
  path = get_test_path(path)

  command = %Q[ruby -I"lib:test" #{path}]
  command << " -n #{get_test_name(name)}" unless name.nil?

  system command
end

.get_test_name(name) ⇒ Object



57
58
59
# File 'lib/test/this.rb', line 57

def self.get_test_name(name)
  "#{test_method_prefix}#{name.gsub(' ', '_')}"
end

.get_test_path(path) ⇒ Object



53
54
55
# File 'lib/test/this.rb', line 53

def self.get_test_path(path)
  File.join(test_path, "#{path}#{file_suffix}")
end