Last active
November 10, 2020 16:10
-
-
Save jmbruel/27accefc036dae4773b45027346002e5 to your computer and use it in GitHub Desktop.
Test for the Strategy pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# usage: ruby checkModel.rb [file] | |
# ------------------- | |
# Author:: Jean-Michel Bruel (mailto:[email protected]) improved by JMI | |
# Copyright:: Copyright (c) 2014--2020 JMB | |
# License:: Distributes under the same terms as Ruby | |
# ------------------- | |
require "minitest/autorun" | |
MODEL_NAME = ARGV[0] ? ARGV[0] : "TP1.plantuml" | |
module MiniTest | |
class Unit | |
class TestCase | |
#Define new assertion | |
def assert_contains(string_to_test, substring_to_verify) | |
assert_match( string_to_test, substring_to_verify) | |
end | |
def assert_not_contains(string_to_test, substring_to_verify) | |
assert_not_match( string_to_test, substring_to_verify) | |
end | |
end | |
end | |
end | |
MiniTest::Unit.after_tests { p @_assertions } | |
class TestGeneratedModel < MiniTest::Unit::TestCase | |
#------------ General tests about plantUML | |
def test_generated_model_exists | |
assert_equal(true, File.exists?(MODEL_NAME)) | |
end | |
def test_generated_model_is_plantuml | |
assert_equal(true, File.readlines(MODEL_NAME).grep(/@startuml/).any?) | |
assert_equal(true, File.readlines(MODEL_NAME).grep(/@enduml/).any?) | |
end | |
#------------ Specific tests about expected content | |
def test_class_Character_is_abstract | |
assert_equal(true, File.readlines(MODEL_NAME).grep(/abstract class Character\s*/).any?) | |
end | |
def test_class_Character_has_BehaviorWeapon | |
assert_contains(/Character\s+[o|"<>"]-+> "[\d|.]" BehaviorWeapon/, File.readlines(MODEL_NAME).join) | |
end | |
def test_BehaviorWeapon_is_an_Interface | |
assert_equal(true, File.readlines(MODEL_NAME).grep(/interface\s+BehaviorWeapon/).any?) | |
end | |
def test_BehaviorWeapon_Interface_has_concrete_implementation | |
assert_equal(true, File.readlines(MODEL_NAME).grep(/BehaviorWeapon\s+<\|\.\./).any?) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment