Skip to content

Commit

Permalink
Extract part of #remove_past_results and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Stewart committed Dec 5, 2012
1 parent 7db9d28 commit 1d245a5
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 6 deletions.
22 changes: 16 additions & 6 deletions lib/gitnesse/wiki.rb
Expand Up @@ -94,14 +94,24 @@ def remove_past_results


if page if page
content = page.raw_data content = page.raw_data
if content.match(/\u0060{3}gherkin.*\u0060{3}(.*)/m)[1] content = strip_results(content)
[ "FAILED", "PASSED", "PENDING", "UNDEFINED" ].each do |type| @wiki.update_page(page, page.name, :markdown, content, @commit_info)
content.gsub!(/#{type}: .*\n/, '') end
end end
@wiki.update_page(page, page.name, :markdown, content, @commit_info) 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
end end
content
end end


# Public: Appends results of cucumber scenario to wiki # Public: Appends results of cucumber scenario to wiki
Expand Down
56 changes: 56 additions & 0 deletions 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

0 comments on commit 1d245a5

Please sign in to comment.