require_relative '../test_helper' module Generator class ImplementationTest < Minitest::Test FixturePaths = Paths.new( metadata: 'test/fixtures/metadata', track: 'test/fixtures/xruby' ) def test_version subject = Implementation.new(paths: FixturePaths, slug: 'alpha') assert_equal 1, subject.version end def test_slug subject = Implementation.new(paths: FixturePaths, slug: 'alpha') assert_equal 'alpha', subject.slug end def test_update_tests_version mock_file = Minitest::Mock.new.expect :write, '2'.length, [2] subject = Implementation.new(paths: FixturePaths, slug: 'alpha') # Verify iniital condition from fixture file assert_equal 1, subject.tests_version.to_i File.stub(:open, true, mock_file) do assert_equal 2, subject.update_tests_version end mock_file.verify end def test_update_example_solution expected_content = "# This is the example\n\nclass BookKeeping\n VERSION = 1\nend\n" mock_file = Minitest::Mock.new.expect :write, expected_content.length, [expected_content] subject = Implementation.new(paths: FixturePaths, slug: 'alpha') File.stub(:open, true, mock_file) do assert_equal expected_content, subject.update_example_solution end mock_file.verify end def test_create_tests_file # Q: Is the pain here caused by: # a) Implementation `including` everything rather than using composition? # b) Trying to verify the expected content. # c) The expected content being too long # # Q: Where in the call stack should the testing logically stop? # A: It should be able to stop when minitest_tests is called with the correct arguments. expected_content =<