[WIP] generator: refactor implementation, part 1#641
[WIP] generator: refactor implementation, part 1#641hilary wants to merge 10 commits intoexercism:masterfrom
Conversation
#available shouldn't depend on the existence of a '<mumble>_case.rb' file, because that might go away or get changed. We can just look for the presence of a .meta/generator directory.
leftover from the proc days
Two reasons. Main reason: Implementation shouldn't be thinking in terms of files. Secondary reason, old name was misleading, as it regenerates the file when it exists :(
| def test_slug | ||
| subject = Implementation.new(paths: FixturePaths, slug: 'alpha') | ||
| assert_equal 'alpha', subject.slug | ||
| end |
There was a problem hiding this comment.
This is not a test of core ruby functionality, it is a test that Implementation responds to slug.
Request: Keep this test.
Edit: But it needs to be deleted in the next commit anyway (for a different reason), so squash these two commits together.
|
|
||
| def camel_case | ||
| underscore.split('_').map(&:capitalize).join | ||
| end |
There was a problem hiding this comment.
- I'm sceptical of any change that is an "add" as part of a 'refactor' commit.
- This change makes the class name
Underscoreinaccurate.
| module GeneratorCases | ||
| class << self | ||
| def available(track_path) | ||
| cases_filepaths(track_path).map { |filepath| slugify(filepath) }.sort |
There was a problem hiding this comment.
I strongly disagree with this change.
It is true that available does not need to know exactly how a test case is generated, and you could achieve this by abstracting out the availability criteria, but since that is all this class does that seems excessive.
because that might go away or get changed.
This is a case of YAGNI and we can worry about that when it happens.
See also: #646 which aims to give new generator implementers helpful advice.
Request: Omit this commit.
|
|
||
| def test_name | ||
| exercise = Exercise.new(slug: 'alpha-beta') | ||
| assert_equal 'alpha_beta', exercise.name |
There was a problem hiding this comment.
Yay for tests.
I'm not sure name is the right name for this property, but it is consistent with what we've been using.
| end | ||
|
|
||
| class ClassBasedTestTemplateValuesFactory | ||
| class ClassBasedTestTemplateValuesFactory < TestTemplateValuesFactory |
There was a problem hiding this comment.
You like tests to be way more DRY than I do.
I'm not sure this is a good idea.
(But it's not wrong.)
| include TemplateValuesFactory | ||
| end | ||
|
|
||
| class ClassBasedTestTemplateValuesFactory < TestTemplateValuesFactory |
| } | ||
| end | ||
|
|
||
| def test_abbreviated_commit_hash |
There was a problem hiding this comment.
Again, not core ruby functionality.
That it is implemented using an attr_reader is irrelevant.
Request: omit this commit.
|
|
||
| def exercise_name_camel | ||
| exercise_name.split('_').map(&:capitalize).join | ||
| exercise.name.camel_case |
There was a problem hiding this comment.
slug is the canonical value for problem identity.
This should be exercise.slug.camel_case
But either way it's a Demeter violation, so should be just exercise.test_class_name
exercise_name_camel is a slightly misleading method name here given it's usage is to determine the test class name used in the template. But this should be a separate PR/refactoring. Issue: #651
| @@ -3,20 +3,27 @@ module Generator | |||
| class TemplateValues | |||
There was a problem hiding this comment.
The original intention of TemplateValues was that it it should be a dumb container and would only contain the template values available to the erb file. The initialize method provided one place where it was possible to see exactly all the properties that would be available to the erb.
It is the responsibility of the TemplateValuesFactory to construct the necessary values.
If that is the goal, then there is probably a nicer way of implementing this but I'm not sure this commit is heading in that direction.
| # Doesn't update the version information. | ||
| class GenerateTests < ImplementationDelegator | ||
| def call | ||
| create_tests_file |
|
I've extracted the best parts from this PR in: #677 and will continue the refactoring from there. |
I did this PR in two parts. The first part (this one) separates out the Exercise model.
The second part (two different PRs) separates out the Repository model in two different ways. One PR creates a Repository which is instantiated with paths only. The second PR creates a Repository which is instantiated with paths and exercise.