Permalink
Browse files

Added a few specs and a rake task to run them (rake spec)

The output will be in color if
the minitest gem is installed.
(Thanks to minitest/pride)
  • Loading branch information...
peterhellberg committed Jun 7, 2012
1 parent addfb22 commit 83ff630e8fb037943eb5420a0fe86c0600138840
Showing with 51 additions and 0 deletions.
  1. +4 −0 Rakefile
  2. +15 −0 spec/spec_helper.rb
  3. +32 −0 spec/xkcd_spec.rb
View
@@ -4,5 +4,9 @@ Rake::TestTask.new do |t|
t.libs << 'test'
end
+Rake::TestTask.new(:spec) do |t|
+ t.test_files = FileList['spec/**/*_spec.rb']
+end
+
desc "Run tests"
task :default => :test
View
@@ -0,0 +1,15 @@
+# encoding: utf-8
+
+require 'minitest/autorun'
+require 'minitest/spec'
+
+begin
+ require 'minitest/pride'
+rescue LoadError
+ # Continue, but without colors
+end
+
+# Note that relative requirements
+# are only available in Ruby 1.9
+#
+require_relative '../lib/xkcd.rb'
View
@@ -0,0 +1,32 @@
+# encoding: utf-8
+
+require_relative 'spec_helper.rb'
+
+# Specs for the XKCD class
+#
+describe XKCD do
+
+ # The comic class method
+ #
+ describe "comic" do
+ it "should return the URI for a random comic" do
+ XKCD.comic.must_match /^http:\/\/xkcd\.com\/\d{1,4}\/$/
+ end
+ end
+
+ # The get alias method
+ #
+ describe "get" do
+ it "should return the URI for a random comic" do
+ XKCD.get.must_match /^http:\/\/xkcd\.com\/\d{1,4}\/$/
+ end
+ end
+
+ # The img class method
+ #
+ describe "img" do
+ it "should return the ALT text and URI of the image for a random comic" do
+ XKCD.img.must_match /^.+ : http:\/\/imgs\.xkcd\.com\/comics\/.+\.(png|jpg)$/
+ end
+ end
+end

0 comments on commit 83ff630

Please sign in to comment.