Class: Daigaku::Test

Inherits:
Object
  • Object
show all
Defined in:
lib/daigaku/test.rb

Constant Summary collapse

CODE_REGEX =
/\[\['solution::code'\]\]/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Test

Returns a new instance of Test.



10
11
12
13
# File 'lib/daigaku/test.rb', line 10

def initialize(path)
  @unit_path = path
  @path = Dir[File.join(path, '*spec.rb')].first
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/daigaku/test.rb', line 6

def path
  @path
end

Instance Method Details

#run(solution_code) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/daigaku/test.rb', line 15

def run(solution_code)
  spec_code = File.read(@path)
  patched_spec_code = insert_code(spec_code, solution_code.to_s)

  temp_spec = File.join(File.dirname(@path), "temp_#{File.basename(@path)}")
  create_temp_spec(temp_spec, patched_spec_code)

  result = %x{ rspec --color --format j #{temp_spec} }
  remove_file(temp_spec)

  TestResult.new(result)
end