Permalink
Browse files

Extract part of #remove_past_results and add test

  • Loading branch information...
1 parent 7db9d28 commit 1d245a59cd5bd6cfc198a95a82b3ab2ba958ce02 @stewart stewart committed Dec 5, 2012
Showing with 72 additions and 6 deletions.
  1. +16 −6 lib/gitnesse/wiki.rb
  2. +56 −0 test/lib/gitnesse/strip_results_test.rb
View
@@ -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
@@ -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

0 comments on commit 1d245a5

Please sign in to comment.