From 1d245a59cd5bd6cfc198a95a82b3ab2ba958ce02 Mon Sep 17 00:00:00 2001 From: Andrew Stewart Date: Tue, 4 Dec 2012 21:32:47 -0800 Subject: [PATCH] Extract part of #remove_past_results and add test --- lib/gitnesse/wiki.rb | 22 +++++++--- test/lib/gitnesse/strip_results_test.rb | 56 +++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 6 deletions(-) create mode 100644 test/lib/gitnesse/strip_results_test.rb diff --git a/lib/gitnesse/wiki.rb b/lib/gitnesse/wiki.rb index 2cf2e37..ffa5973 100644 --- a/lib/gitnesse/wiki.rb +++ b/lib/gitnesse/wiki.rb @@ -94,14 +94,24 @@ def remove_past_results if page content = page.raw_data - if content.match(/\u0060{3}gherkin.*\u0060{3}(.*)/m)[1] - [ "FAILED", "PASSED", "PENDING", "UNDEFINED" ].each do |type| - content.gsub!(/#{type}: .*\n/, '') - end - @wiki.update_page(page, page.name, :markdown, content, @commit_info) - end + content = strip_results(content) + @wiki.update_page(page, page.name, :markdown, content, @commit_info) + end + end + end + + # Public: Strips old cucumber results + # + # content - the string to remote old results from + # + # Returns a string + def strip_results(content) + if content.match(/\u0060{3}gherkin.*\u0060{3}(.*)/m)[1] + [ "FAILED", "PASSED", "PENDING", "UNDEFINED" ].each do |type| + content.gsub!(/#{type}: .*\n*/, '') end end + content end # Public: Appends results of cucumber scenario to wiki diff --git a/test/lib/gitnesse/strip_results_test.rb b/test/lib/gitnesse/strip_results_test.rb new file mode 100644 index 0000000..d78f06b --- /dev/null +++ b/test/lib/gitnesse/strip_results_test.rb @@ -0,0 +1,56 @@ +require_relative "../../test_helper" + +describe Gitnesse::Wiki do + describe "#strip_results" do + let(:wiki_page) do + <<-EOS +```gherkin +Feature: Division + In order to avoid silly mistakes + As a math idiot + I want to be told the quotient of 2 numbers + + Scenario: Divide two numbers + Given I have entered 6 into the calculator + And I have entered 2 into the calculator + When I divide + Then the result should be 3 +``` + +UNDEFINED: Divide two numbers + +PENDING: Divide two numbers + +FAILED: Divide two numbers + +PASSED: Divide two numbers +EOS + end + + let(:expected_result) do + <<-EOS +```gherkin +Feature: Division + In order to avoid silly mistakes + As a math idiot + I want to be told the quotient of 2 numbers + + Scenario: Divide two numbers + Given I have entered 6 into the calculator + And I have entered 2 into the calculator + When I divide + Then the result should be 3 +``` + +EOS + end + + before do + Gollum::Wiki.expects(:new).returns(mock) + end + + it "strips old results from the page" do + Gitnesse::Wiki.new(Dir.mktmpdir).strip_results(wiki_page).must_equal expected_result + end + end +end