require 'rexml/document' TARGET_MATCH = /the feature/ Transform /^the feature$/ do |feauture| @cache[:feature] end Given /^the feature file, '([^']+)', is the (feature) for the scenario$/ do |name,type| @cache[type.to_sym] = name end Then /^I expect (#{TARGET_MATCH}) file (\w+) to exist at '([^']+)'$/ do |target,file_type,path| file = "#{$env[:documents]}/#{path}/#{target}.#{file_type}" File.should exist(file) file end Then /^I expect the feature title to be '([^']+)'$/ do |title| xml = REXML::Document.new(File.open("doc/requirements/features/features.html")) actual_title = xml.elements["//title"].text actual_title.should == title end Then /^I expect the feature heading to be '([^']+)'$/ do |title| xml = REXML::Document.new(File.open("doc/requirements/features/features.html")) actual_title = "#{xml.elements["//*[@class='feature']/*[@class='title']/*[@class='pre']"].text} " + "#{xml.elements["//*[@class='feature']/*[@class='title']/*[@class='name']"].text}" actual_title.should == title end Then /^I expect the feature to have the (@\w+) tag$/ do |tag| xml = REXML::Document.new(File.open("doc/requirements/features/features.html")) found = false xml.elements.each("//*[@class='feature']//*[@class='tags']/a") do |actual_tag| found = true if actual_tag.text == tag end found.should be_true end Then /^I expect the feature description to be$/ do |description| xml = REXML::Document.new(File.open("doc/requirements/features/features.html")) xml.elements["//*[@class='feature']//*[@class='description']"].text.strip.should == description.strip end Then /^I expect the feature to have a background$/ do xml = REXML::Document.new(File.open("doc/requirements/features/features.html")) xml.elements["//*[@id='background']"].should_not be_nil end Then /^I expect the background to have steps?$/ do |string| found = true xml = REXML::Document.new(File.open("doc/requirements/features/features.html")) xml.elements["//*[@id='backgroundSteps']"].elements.each do |step| found = true if "#{step.elements["span[1]"].text}#{step.elements["span[2]"].text}" == string end found.should be_true end Then /^I expect the feature to have the scenarios:$/ do |string| xml = REXML::Document.new(File.open("doc/requirements/features/features.html")) string.split("\n").each do |expected_title| found = nil xml.elements.each("//*[@class='scenario']/*[@class='title']/*[@class='name']") do |scenario| found = scenario if scenario.text == expected_title end found.should_not be_nil end end