Skip to content
Browse files

Fixes the tests so that they can execute on their own.

Speed benchmarks:

```
$ rake
test:file[test/services/subscriber_to_feed_data_converter_test.rb]

6 tests, 1 assertions, 1 failures, 5 errors, 0 skips
```

```
$ rake
test:file[test/services/subscriber_to_feed_data_converter_test.rb]

Finished tests in 0.005167s, 1161.2156 tests/s, 2128.8953 assertions/s.

```

Fair enough.
  • Loading branch information...
1 parent 4c88b88 commit 5752849fb1aaaa39112abc3123b9946abda0d3e1 @wilkie wilkie committed Feb 19, 2013
Showing with 50 additions and 45 deletions.
  1. +50 −45 test/services/subscriber_to_feed_data_converter_test.rb
View
95 test/services/subscriber_to_feed_data_converter_test.rb
@@ -1,6 +1,9 @@
require 'minitest/autorun'
require 'mocha/setup'
+
require 'socket'
+require_relative '../../app/models/feed_data'
+require_relative '../../app/services/finger_service'
require_relative '../../app/services/subscriber_to_feed_data_converter'
FakeFingerData = Struct.new(:url)
@@ -9,71 +12,73 @@ module RstatUs
class InvalidSubscribeTo < StandardError; end
end
-describe "converting a subscriber to feed data" do
- describe "when a Safari 'feed://' scheme is provided" do
- it "should replace feed:// with http://" do
- feed_data = SubscriberToFeedDataConverter.new("feed://stuff").get_feed_data!
+describe SubscriberToFeedDataConverter do
+ describe "converting a subscriber to feed data" do
+ describe "when a Safari 'feed://' scheme is provided" do
+ it "should replace feed:// with http://" do
+ feed_data = SubscriberToFeedDataConverter.new("feed://stuff").get_feed_data!
- assert_equal "http://stuff", feed_data.url
+ assert_equal "http://stuff", feed_data.url
+ end
end
- end
- describe "when an email address is provided" do
- it "should finger the user" do
- email = "somebody@somewhere.com"
+ describe "when an email address is provided" do
+ it "should finger the user" do
+ email = "somebody@somewhere.com"
- mock_finger_service = mock
- FingerService.expects(:new).with(email).returns(mock_finger_service)
+ mock_finger_service = mock
+ FingerService.expects(:new).with(email).returns(mock_finger_service)
- finger_data = FakeFingerData.new("url")
- mock_finger_service.expects(:finger!).returns(finger_data)
+ finger_data = FakeFingerData.new("url")
+ mock_finger_service.expects(:finger!).returns(finger_data)
- new_feed_data = SubscriberToFeedDataConverter.new(email).get_feed_data!
+ new_feed_data = SubscriberToFeedDataConverter.new(email).get_feed_data!
- assert_equal "url", new_feed_data.url
- assert_equal finger_data, new_feed_data
+ assert_equal "url", new_feed_data.url
+ assert_equal finger_data, new_feed_data
+ end
end
- end
- describe "when an http:// URL is provided" do
- it "should use the subscriber URL as the feed URL" do
- feed_url = "http://feed.me"
- feed_data = SubscriberToFeedDataConverter.new(feed_url).get_feed_data!
+ describe "when an http:// URL is provided" do
+ it "should use the subscriber URL as the feed URL" do
+ feed_url = "http://feed.me"
+ feed_data = SubscriberToFeedDataConverter.new(feed_url).get_feed_data!
- assert_equal feed_url, feed_data.url
+ assert_equal feed_url, feed_data.url
+ end
end
- end
- describe "when an https:// URL is provided" do
- it "should use the subscriber URL as the feed URL" do
- feed_url = "https://feed.me"
- feed_data = SubscriberToFeedDataConverter.new(feed_url).get_feed_data!
+ describe "when an https:// URL is provided" do
+ it "should use the subscriber URL as the feed URL" do
+ feed_url = "https://feed.me"
+ feed_data = SubscriberToFeedDataConverter.new(feed_url).get_feed_data!
- assert_equal feed_url, feed_data.url
+ assert_equal feed_url, feed_data.url
+ end
end
- end
- describe "when we cannot currently understand the subscriber URL" do
- it "should raise an exception so that we dont try and look it up as a file" do
- feed_url = "Gemfile.lock"
+ describe "when we cannot currently understand the subscriber URL" do
+ it "should raise an exception so that we dont try and look it up as a file" do
+ feed_url = "Gemfile.lock"
- lambda {
- SubscriberToFeedDataConverter.new(feed_url).get_feed_data!
- }.must_raise(RstatUs::InvalidSubscribeTo)
+ lambda {
+ SubscriberToFeedDataConverter.new(feed_url).get_feed_data!
+ }.must_raise(RstatUs::InvalidSubscribeTo)
+ end
end
- end
- describe "when a network error occurs retrieving the subscriber info" do
- it "consumes the SocketError and re-raises at an RstatUs exception" do
- email = "ladygaga@twitter"
+ describe "when a network error occurs retrieving the subscriber info" do
+ it "consumes the SocketError and re-raises at an RstatUs exception" do
+ email = "ladygaga@twitter"
- mock_finger_service = mock
- FingerService.expects(:new).with(email).returns(mock_finger_service)
- mock_finger_service.expects(:finger!).throws(SocketError)
+ mock_finger_service = mock
+ FingerService.expects(:new).with(email).returns(mock_finger_service)
+ mock_finger_service.expects(:finger!).throws(SocketError)
- lambda {
- SubscriberToFeedDataConverter.new(email).get_feed_data!
- }.must_raise(RstatUs::InvalidSubscribeTo)
+ lambda {
+ SubscriberToFeedDataConverter.new(email).get_feed_data!
+ }.must_raise(RstatUs::InvalidSubscribeTo)
+ end
end
end
end

0 comments on commit 5752849

Please sign in to comment.
Something went wrong with that request. Please try again.