Permalink
Browse files

Added test for Gitnesse::Wiki#append_results

  • Loading branch information...
1 parent bd19b29 commit a15744f8b5d63b22cf08748feff8dac559acf493 @stewart stewart committed Dec 7, 2012
Showing with 53 additions and 3 deletions.
  1. +3 −3 lib/gitnesse/wiki.rb
  2. +50 −0 test/lib/gitnesse/wiki_append_results_test.rb
View
@@ -118,20 +118,20 @@ def strip_results(content)
#
# scenario - Cucumber scenario from After hook
#
- # Returns nothing
+ # Returns a string containing the scenario result
def append_results(scenario)
- pages = @wiki.pages
filename = File.basename(scenario.feature.file, ".feature")
@commit_info[:message] = Gitnesse.configuration.info
- pages.each do |page|
+ self.pages.each do |page|
if page.name == filename || page.name == "#{filename}.feature"
if page.text_data.include? scenario.name
content = page.raw_data
string = "\n\`Last result was #{scenario.status.to_s.upcase}: #{scenario.name} (#{Time.now.to_s} - #{Gitnesse.configuration.info})\`\n"
content.gsub(string, '')
content << string
@wiki.update_page(page, page.name, :markdown, content, @commit_info)
+ return string
end
end
end
@@ -0,0 +1,50 @@
+require_relative '../../test_helper'
+
+describe Gitnesse::Wiki do
+ describe "#append_results" do
+ let(:dir) { Dir.mktmpdir }
+ let(:wiki) { mock }
+ let(:feature_file) do
+ <<-EOS
+```gherkin
+Feature: Addition
+ In order to avoid silly mistakes
+ I want to be told the sum of two numbers
+
+ Scenario: Add two single digit numbers
+ Given I have entered 7 into the calculator
+ And I have entered 5 into the calculator
+ When I add
+ Then the result should be 12 on the screen
+```
+ EOS
+ end
+ let(:pages) do
+ [
+ stub(
+ :name => "addition",
+ :text_data => feature_file,
+ :raw_data => feature_file
+ )
+ ]
+ end
+ let(:cucumber_scenario) do
+ stub(
+ :name => "Add two single digit numbers",
+ :status => :passed,
+ :feature => stub(:file => "addition.feature")
+ )
+ end
+
+ let(:method) { lambda { Gitnesse::Wiki.new(dir).append_results(cucumber_scenario) } }
+
+ before do
+ Gollum::Wiki.expects(:new).returns(wiki)
+ wiki.expects(:pages).returns(pages)
+ wiki.expects(:update_page).returns(true)
+ File.expects(:basename).returns("addition")
+ end
+
+ it { puts method.call.must_include "Last result was PASSED: Add two single digit numbers" }
+ end
+end

0 comments on commit a15744f

Please sign in to comment.