Skip to content

Commit 77b5565

Browse files
authored
Merge pull request #503 from Insti/start_unit_testing_generator
Start unit testing lib/generator
2 parents d2f08e8 + 3df6a04 commit 77b5565

File tree

7 files changed

+56
-5
lines changed

7 files changed

+56
-5
lines changed

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
22

33
gem 'minitest'
44
gem 'rubocop', '0.36.0'
5+
gem 'simplecov'
6+
gem 'rake'

Rakefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
require 'rake'
2+
require 'rake/testtask'
3+
4+
Rake::TestTask.new do |task|
5+
task.pattern = 'test/*_test.rb'
6+
end

bin/executable-tests-check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ require 'minitest/autorun'
33

44
# Assume that this file lives in #{base}/bin
55
base = File.join(__dir__,'..')
6-
files = Dir.glob("#{base}/**/*test.rb") + Dir.glob("#{base}/bin/*")
6+
files = Dir.glob("#{base}/exercises/**/*test.rb") + Dir.glob("#{base}/bin/*")
77

88
files.each do |file|
99
describe file do

config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,8 @@
517517
"ignored": [
518518
"docs",
519519
"img",
520-
"lib"
520+
"lib",
521+
"test"
521522
],
522523
"foregone": [
523524

lib/generator.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,22 @@ class Generator
88
METADATA_REPOSITORY = 'x-common'.freeze
99

1010
attr_reader :name, :cases
11-
def initialize(name, cases)
11+
def initialize(name, cases, metadata_repository_path=nil)
1212
@name = name
1313
@cases = cases
14+
@metadata_repository_path = metadata_repository_path || default_metadata_path
15+
end
16+
17+
def default_metadata_path
18+
File.join( '..', METADATA_REPOSITORY)
1419
end
1520

1621
def metadata_dir
17-
File.expand_path(File.join('..', '..', '..', METADATA_REPOSITORY, 'exercises', name), __FILE__)
22+
File.join(@metadata_repository_path, 'exercises', name)
1823
end
1924

2025
def exercise_dir
21-
File.expand_path(File.join('..', '..', 'exercises', name), __FILE__)
26+
File.join('exercises', name)
2227
end
2328

2429
def exercise_meta_dir

test/generator_test.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
require_relative 'test_helper'
2+
3+
class GeneratorTest < Minitest::Test
4+
def test_default_metadata_path
5+
subject = Generator.new('aname', nil)
6+
# This is relative to the xruby root
7+
assert_equal '../x-common/exercises/aname', subject.metadata_dir
8+
end
9+
10+
def test_initalize_with_fixture_path
11+
fixture_path = 'xruby/test/fixtures'
12+
subject = Generator.new('aname', nil, fixture_path)
13+
assert_equal 'xruby/test/fixtures/exercises/aname', subject.metadata_dir
14+
end
15+
16+
def test_exercise_dir
17+
subject = Generator.new('aname', nil)
18+
# This is relative to the xruby root
19+
assert_equal 'exercises/aname', subject.exercise_dir
20+
end
21+
end

test/test_helper.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
2+
3+
require 'simplecov'
4+
require 'minitest/autorun'
5+
require 'minitest/pride'
6+
7+
SimpleCov.start do
8+
add_filter '/tests/'
9+
add_group 'Utilities' do |file|
10+
!(file.filename =~ /_cases\.rb$/)
11+
end
12+
add_group 'Cases', '_cases.rb'
13+
end
14+
15+
# So we can be sure we have coverage on the whole lib directory:
16+
Dir.glob('lib/*.rb').each { |file| require file.gsub(%r{(^lib\/|\.rb$)}, '') }

0 commit comments

Comments
 (0)