Module: Test::This

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

Constant Summary collapse

VERSION =
'0.1.0'

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.file_suffixObject

Returns the value of attribute file_suffix.



13
14
15
# File 'lib/test/this.rb', line 13

def file_suffix
  @file_suffix
end

.minitest_method_prefixObject

Returns the value of attribute minitest_method_prefix.



13
14
15
# File 'lib/test/this.rb', line 13

def minitest_method_prefix
  @minitest_method_prefix
end

.test_pathObject

Returns the value of attribute test_path.



13
14
15
# File 'lib/test/this.rb', line 13

def test_path
  @test_path
end

Instance Attribute Details

#file_suffixObject



9
10
11
12
13
14
15
16
17
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/test/this.rb', line 9

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

  class << self
    attr_accessor :file_suffix, :minitest_method_prefix, :test_path
  end

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

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

  def self.suite
    @suite ||= :rails
  end

  def self.suite=(value)
    return @suite = value if [:rails, :minitest].include?(value)

    fail ArgumentError, "unknown test suite: #{value}"
  end

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

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

    command = %Q[ruby -I"lib:test" #{path}]
    command << " -n #{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)
    return if "#{name}".empty?

    case suite
    when :rails then name
    when :minitest then "#{minitest_method_prefix}#{name.gsub(' ', '_')}"
    else fail
    end
  end
end

#minitest_method_prefixObject



9
10
11
12
13
14
15
16
17
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/test/this.rb', line 9

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

  class << self
    attr_accessor :file_suffix, :minitest_method_prefix, :test_path
  end

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

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

  def self.suite
    @suite ||= :rails
  end

  def self.suite=(value)
    return @suite = value if [:rails, :minitest].include?(value)

    fail ArgumentError, "unknown test suite: #{value}"
  end

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

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

    command = %Q[ruby -I"lib:test" #{path}]
    command << " -n #{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)
    return if "#{name}".empty?

    case suite
    when :rails then name
    when :minitest then "#{minitest_method_prefix}#{name.gsub(' ', '_')}"
    else fail
    end
  end
end

#suiteObject



9
10
11
12
13
14
15
16
17
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/test/this.rb', line 9

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

  class << self
    attr_accessor :file_suffix, :minitest_method_prefix, :test_path
  end

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

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

  def self.suite
    @suite ||= :rails
  end

  def self.suite=(value)
    return @suite = value if [:rails, :minitest].include?(value)

    fail ArgumentError, "unknown test suite: #{value}"
  end

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

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

    command = %Q[ruby -I"lib:test" #{path}]
    command << " -n #{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)
    return if "#{name}".empty?

    case suite
    when :rails then name
    when :minitest then "#{minitest_method_prefix}#{name.gsub(' ', '_')}"
    else fail
    end
  end
end

#test_pathObject



9
10
11
12
13
14
15
16
17
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/test/this.rb', line 9

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

  class << self
    attr_accessor :file_suffix, :minitest_method_prefix, :test_path
  end

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

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

  def self.suite
    @suite ||= :rails
  end

  def self.suite=(value)
    return @suite = value if [:rails, :minitest].include?(value)

    fail ArgumentError, "unknown test suite: #{value}"
  end

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

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

    command = %Q[ruby -I"lib:test" #{path}]
    command << " -n #{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)
    return if "#{name}".empty?

    case suite
    when :rails then name
    when :minitest then "#{minitest_method_prefix}#{name.gsub(' ', '_')}"
    else fail
    end
  end
end

Class Method Details

.execute(path, name = nil) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/test/this.rb', line 38

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

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

  system command
end

.get_test_name(name) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/test/this.rb', line 52

def self.get_test_name(name)
  return if "#{name}".empty?

  case suite
  when :rails then name
  when :minitest then "#{minitest_method_prefix}#{name.gsub(' ', '_')}"
  else fail
  end
end

.get_test_path(path) ⇒ Object



48
49
50
# File 'lib/test/this.rb', line 48

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

.suiteObject



24
25
26
# File 'lib/test/this.rb', line 24

def self.suite
  @suite ||= :rails
end

.suite=(value) ⇒ Object



28
29
30
31
32
# File 'lib/test/this.rb', line 28

def self.suite=(value)
  return @suite = value if [:rails, :minitest].include?(value)

  fail ArgumentError, "unknown test suite: #{value}"
end