tracks/ruby/test/generator/implementation_test.rb in trackler-2.1.0.36 vs tracks/ruby/test/generator/implementation_test.rb in trackler-2.1.0.37

- old
+ new

@@ -6,22 +6,18 @@ metadata: 'test/fixtures/metadata', track: 'test/fixtures/xruby' ) def test_version - subject = Implementation.new(paths: FixturePaths, slug: 'alpha') + exercise = Minitest::Mock.new.expect :slug, 'alpha' + subject = Implementation.new(paths: FixturePaths, exercise: exercise) 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') + subject = Implementation.new(paths: FixturePaths, exercise: Exercise.new(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 @@ -29,18 +25,18 @@ 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') + subject = Implementation.new(paths: FixturePaths, exercise: Exercise.new(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 + def test_build_tests # 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 # @@ -82,37 +78,33 @@ assert_equal 1, BookKeeping::VERSION end end TESTS_FILE mock_file = Minitest::Mock.new.expect :write, expected_content.length, [expected_content] - subject = Implementation.new(paths: FixturePaths, slug: 'alpha') + subject = Implementation.new(paths: FixturePaths, exercise: Exercise.new(slug: 'alpha')) GitCommand.stub(:abbreviated_commit_hash, '123456789') do File.stub(:open, true, mock_file) do - assert_equal expected_content, subject.create_tests_file + assert_equal expected_content, subject.build_tests end end mock_file.verify # Don't pollute the namespace Object.send(:remove_const, :AlphaCase) end - - def test_exercise_name - subject = Implementation.new(paths: FixturePaths, slug: 'alpha-beta') - assert_equal 'alpha_beta', subject.exercise_name - end end class LoggingImplementationTest < Minitest::Test - def test_create_tests_file + def test_build_tests + exercise = Exercise.new(slug: 'alpha') mock_implementation = Minitest::Mock.new - mock_implementation.expect :create_tests_file, nil - mock_implementation.expect :slug, 'alpha' + mock_implementation.expect :build_tests, nil + mock_implementation.expect :exercise, exercise mock_implementation.expect :version, 2 mock_logger = Minitest::Mock.new mock_logger.expect :info, nil, ['Generated alpha tests version 2'] subject = LoggingImplementation.new(implementation: mock_implementation, logger: mock_logger) - subject.create_tests_file + subject.build_tests mock_implementation.verify end def test_update_tests_version