Skip to content

Commit 594526d

Browse files
committed
Create stub program for outputting JSON
1 parent d603680 commit 594526d

File tree

10 files changed

+103
-9
lines changed

10 files changed

+103
-9
lines changed

Gemfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ git_source(:github) do |repo_name|
66
end
77

88
gem 'rake'
9-
gem 'mandate'
9+
gem 'json'
10+
gem 'activesupport'
1011

1112
group :test do
1213
gem 'minitest', '~> 5.10', '!= 5.10.2'
14+
gem 'minitest-stub-const'
15+
gem 'mocha'
1316
end

Gemfile.lock

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,34 @@
11
GEM
22
remote: https://rubygems.org/
33
specs:
4-
mandate (0.2.0)
4+
activesupport (5.2.2)
5+
concurrent-ruby (~> 1.0, >= 1.0.2)
6+
i18n (>= 0.7, < 2)
7+
minitest (~> 5.1)
8+
tzinfo (~> 1.1)
9+
concurrent-ruby (1.1.4)
10+
i18n (1.5.3)
11+
concurrent-ruby (~> 1.0)
12+
json (2.1.0)
13+
metaclass (0.0.4)
514
minitest (5.11.3)
15+
minitest-stub-const (0.6)
16+
mocha (1.7.0)
17+
metaclass (~> 0.0.1)
618
rake (12.3.1)
19+
thread_safe (0.3.6)
20+
tzinfo (1.2.5)
21+
thread_safe (~> 0.1)
722

823
PLATFORMS
924
ruby
1025

1126
DEPENDENCIES
12-
mandate
27+
activesupport
28+
json
1329
minitest (~> 5.10, != 5.10.2)
30+
minitest-stub-const
31+
mocha
1432
rake
1533

1634
BUNDLED WITH

bin/analyze.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
load File.expand_path('../../lib/analyzer.rb', __FILE__)
22

3-
Analyser.analyze(ARGV[0], ARGV[1])
3+
Analyzer.analyze(ARGV[0], ARGV[1])

bin/analyze.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
#!/bin/bash
22

3+
# Usage:
4+
# ./bin/analyze.sh two_fer ~/test/
5+
36
bundle exec ruby bin/analyze.rb $1 $2

lib/analyzer.rb

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1-
module Analyser
1+
EXERCISES = %w{
2+
two_fer
3+
}
4+
5+
require_relative 'exercise_analyzer'
6+
7+
EXERCISES.each do |exercise|
8+
require_relative "exercises/#{exercise}/analyzer"
9+
end
10+
11+
module Analyzer
212
def self.analyze(exercise, path)
3-
p exercise
4-
p path
13+
ExerciseAnalyzer.analyze(exercise, path)
514
end
615
end

lib/exercise_analyzer.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
require 'json'
2+
require 'active_support/inflector'
3+
4+
class ExerciseAnalyzer
5+
def self.analyze(exercise, path)
6+
classified_exercise = exercise.tr('-', '_').classify
7+
analyzer = "#{classified_exercise}Analyzer".constantize.new(path)
8+
analyzer.analyze!
9+
analyzer.report!
10+
end
11+
12+
def initialize(path)
13+
@path = Pathname.new(path)
14+
@approve = false
15+
end
16+
17+
def report!
18+
File.open(path / "analysis.json","w") do |f|
19+
f.write(results.to_json)
20+
end
21+
end
22+
23+
private
24+
attr_reader :path, :approve
25+
26+
def results
27+
{
28+
approve: approve
29+
}
30+
end
31+
end

lib/exercises/two_fer/analyzer.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class TwoFerAnalyzer < ExerciseAnalyzer
2+
def analyze!
3+
end
4+
end

test/analyzer_test.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
class AnalyzerTest < Minitest::Test
44
def test_that_it_runs
5-
flunk
5+
exercise = mock
6+
path = mock
7+
8+
ExerciseAnalyzer.expects(:analyze).with(exercise, path)
9+
Analyzer.analyze(exercise, path)
610
end
711
end

test/exercise_analyzer_test.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
require "test_helper"
2+
3+
class ExerciseAnalyzerTest < Minitest::Test
4+
5+
class ::SomeFakeExerciseAnalyzer < ExerciseAnalyzer
6+
end
7+
8+
def test_that_it_constantizes_correctly
9+
SomeFakeExerciseAnalyzer.any_instance.expects(:analyze!)
10+
SomeFakeExerciseAnalyzer.any_instance.expects(:report!)
11+
ExerciseAnalyzer.analyze('some_fake-exercise', SAFE_WRITE_PATH)
12+
end
13+
end

test/test_helper.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1-
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
1+
gem 'minitest'
22

33
require "minitest/autorun"
4+
require 'minitest/pride'
5+
require "mocha/setup"
6+
7+
class Minitest::Test
8+
SAFE_WRITE_PATH = '/tmp'
9+
end
10+
11+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
12+
require "analyzer"

0 commit comments

Comments
 (0)