spec/page_rankr_spec.rb in PageRankr-3.2.1 vs spec/page_rankr_spec.rb in PageRankr-4.0.0
- old
+ new
@@ -8,10 +8,40 @@
failure_message_for_should do |actual|
"expected that #{actual} would be in #{expected}"
end
end
+RSpec::Matchers.define :be_number do
+ match do |actual|
+ actual.is_a?(Numeric) && actual.send(@symbol, @expected)
+ end
+
+ chain :>= do |expected|
+ @symbol = :>=
+ @expected = expected
+ end
+
+ chain :> do |expected|
+ @symbol = :>
+ @expected = expected
+ end
+
+ chain :< do |expected|
+ @symbol = :<
+ @expected = expected
+ end
+
+ chain :<= do |expected|
+ @symbol = :<=
+ @expected = expected
+ end
+
+ failure_message_for_should do |actual|
+ "expected that #{actual.inspect} would be a number and #{@symbol} than #{@expected}"
+ end
+end
+
describe PageRankr do
describe "#rank_trackers" do
subject{ PageRankr.rank_trackers }
it{ should include(:alexa_us) }
@@ -29,12 +59,12 @@
it{ should have_key(:alexa_us) }
it{ should have_key(:alexa_global) }
it{ should have_key(:google) }
- it{ subject[:alexa_us].should >= 1 }
- it{ subject[:alexa_global].should >= 1 }
+ it{ subject[:alexa_us].should be_number >= 1 }
+ it{ subject[:alexa_global].should be_number >= 1 }
it{ subject[:google].should be_in(0..10) }
end
describe "failure" do
subject do
@@ -72,11 +102,11 @@
PageRankr.backlink_trackers.each do |tracker|
it{ should have_key(tracker) }
it "#{tracker} should have a value greater than zero" do
- subject[tracker].should > 0
+ subject[tracker].should be_number > 0
end
end
end
describe "failure" do
@@ -113,11 +143,11 @@
PageRankr.index_trackers.each do |tracker|
it{ should have_key(tracker) }
it "#{tracker} should have a value greater than zero" do
- subject[tracker].should > 0
+ subject[tracker].should be_number > 0
end
end
end
describe "failure" do
@@ -138,10 +168,10 @@
end
describe "::Site" do
[nil, '', 'batman.thedarkknight'].each do |value|
it "should raise an exception when given #{value.inspect}" do
- expect{PageRankr::Site(value)}.should raise_error(PageRankr::DomainInvalid)
+ expect{PageRankr::Site(value)}.to raise_error(PageRankr::DomainInvalid)
end
end
end
end
\ No newline at end of file