spec/spec_helper.rb in mida-0.2.0 vs spec/spec_helper.rb in mida-0.3.0
- old
+ new
@@ -1,41 +1,18 @@
+require 'bundler/setup'
require 'rspec'
-def element_add_attribute(element, attribute, value)
- if value
- attr = mock(Nokogiri::XML::Attr)
- if value != true
- attr.stub!(:value).and_return(value)
- end
- end
- element.should_receive(:attribute).any_number_of_times.with(attribute).and_return(attr)
- element
+def html_wrap(html)
+ "<!DOCTYPE html><html><body>#{html}</body></html>"
end
-# Return a mock Nokogiri::XML::Element
-def mock_element(tag, attributes={}, inner_text=nil, search_return=[], id_searches={})
- element = mock(Nokogiri::XML::Element)
-
- ['id', 'itemid', 'itemprop', 'itemref', 'itemscope', 'itemtype'].each do |name|
- attributes[name] = nil unless attributes.has_key?(name)
- end
- attributes.each do |name, value|
- element_add_attribute(element, name, value)
- end
-
- element.stub!(:inner_text).and_return(inner_text)
- element.stub!(:name).and_return(tag)
-
- element.should_receive(:search).any_number_of_times.with('./*').and_return(search_return)
-
- # Set a valid return element for each likely id
- ('a'..'z').each do |id|
- stub = element.should_receive(:search).any_number_of_times.with("//*[@id='#{id}']")
- if id_searches.has_key?(id)
- stub.and_return([id_searches[id]])
- else
- stub.and_return([])
- end
- end
-
- element
+# Return the last error message on STDERR.
+# Prevents the message being output to STDERR.
+def last_stderr
+ orig_stderr = $stderr
+ $stderr = StringIO.new
+ yield
+ $stderr.rewind
+ message = $stderr.string.chomp
+ $stderr = orig_stderr
+ message
end