From ff0bd79c530a623c2f049e1c1cbed87e3f6aefaf Mon Sep 17 00:00:00 2001 From: Vit Brunner Date: Tue, 11 Jun 2013 08:59:31 +0100 Subject: [PATCH] Reduce duplication Some would also say it'd be a good idea not to put random stuff in the global namespace. One day I'll figure it out. --- source/scripts/tests/reader/_abstract.coffee | 6 ++++++ source/scripts/tests/reader/json.coffee | 6 +----- source/scripts/tests/reader/markdown.coffee | 6 +----- source/tests.haml | 1 + 4 files changed, 9 insertions(+), 10 deletions(-) create mode 100644 source/scripts/tests/reader/_abstract.coffee diff --git a/source/scripts/tests/reader/_abstract.coffee b/source/scripts/tests/reader/_abstract.coffee new file mode 100644 index 0000000..365b629 --- /dev/null +++ b/source/scripts/tests/reader/_abstract.coffee @@ -0,0 +1,6 @@ +this.testReader = (name, testCases) -> + injector = angular.injector(["ng", "sideBySide"]) + reader = injector.get(name) + + for testCase in testCases + deepEqual(reader(testCase.tested), testCase.expected) diff --git a/source/scripts/tests/reader/json.coffee b/source/scripts/tests/reader/json.coffee index eb1e087..31f8d60 100644 --- a/source/scripts/tests/reader/json.coffee +++ b/source/scripts/tests/reader/json.coffee @@ -1,7 +1,4 @@ test("jsonReader", () -> - injector = angular.injector(["ng", "sideBySide"]) - jsonReader = injector.get("jsonReader") - testCases = [{ tested: """ { @@ -28,6 +25,5 @@ test("jsonReader", () -> } }] - for testCase in testCases - deepEqual(jsonReader(testCase.tested), testCase.expected) + testReader("jsonReader", testCases) ) diff --git a/source/scripts/tests/reader/markdown.coffee b/source/scripts/tests/reader/markdown.coffee index 9f2fa10..ee4d36a 100644 --- a/source/scripts/tests/reader/markdown.coffee +++ b/source/scripts/tests/reader/markdown.coffee @@ -1,7 +1,4 @@ test("markdownReader", () -> - injector = angular.injector(["ng", "sideBySide"]) - markdownReader = injector.get("markdownReader") - testCases = [{ tested: """ Title: Universal Declaration of Human Rights @@ -73,6 +70,5 @@ test("markdownReader", () -> } }] - for testCase in testCases - deepEqual(markdownReader(testCase.tested), testCase.expected) + testReader("markdownReader", testCases) ) diff --git a/source/tests.haml b/source/tests.haml index 8b86676..9791dbe 100644 --- a/source/tests.haml +++ b/source/tests.haml @@ -8,6 +8,7 @@ / test scripts #{stylesheet_link_tag "//cdnjs.cloudflare.com/ajax/libs/qunit/1.11.0/qunit.css"} #{javascript_include_tag "//cdnjs.cloudflare.com/ajax/libs/qunit/1.11.0/qunit.js"} + #{javascript_include_tag "tests/reader/_abstract"} #{javascript_include_tag "tests/reader/markdown"} #{javascript_include_tag "tests/reader/json"}