Permalink
Browse files

cleaning up tests and improving coverage

  • Loading branch information...
ryanb committed Jul 26, 2011
1 parent fdc900e commit 952aafb6548526dd1a2b066d5be2abd063b8560f
@@ -1,7 +1,3 @@
-# These helper methods can be called in your template to set variables to be used in the layout
-# This module should be included in all views globally,
-# to do so you may need to add this line to your ApplicationController
-# helper :layout
module LayoutHelper
def title(page_title, show_title = true)
content_for(:title) { h(page_title.to_s) }
@@ -11,12 +7,4 @@ def title(page_title, show_title = true)
def show_title?
@show_title
end
-
- def stylesheet(*args)
- content_for(:head) { stylesheet_link_tag(*args) }
- end
-
- def javascript(*args)
- content_for(:head) { javascript_include_tag(*args) }
- end
end
@@ -1,30 +1,30 @@
require File.dirname(__FILE__) + '/../spec_helper'
describe CommentsHelper do
- it "should line break properly" do
+ it "handles line breaks properly" do
comment = Factory.build(:comment, :content => "foo\nbar\n\nbaz", :legacy => true)
- helper.format_comment(comment).should == "<p>foo\n<br />bar</p>\n\n<p>baz</p>"
+ helper.format_comment(comment).should eq("<p>foo\n<br />bar</p>\n\n<p>baz</p>")
end
- it "should escape html" do
+ it "escapes html" do
comment = Factory.build(:comment, :content => "<foo>", :legacy => true)
- helper.format_comment(comment).should == "<p>&lt;foo&gt;</p>"
+ helper.format_comment(comment).should eq("<p>&lt;foo&gt;</p>")
end
- it "should use &nbsp; for spaces at beginning of lines" do
+ it "uses &nbsp; for spaces at beginning of lines" do
comment = Factory.build(:comment, :content => " foo bar", :legacy => true)
- helper.format_comment(comment).should == "<p>&nbsp;&nbsp;foo bar</p>"
+ helper.format_comment(comment).should eq("<p>&nbsp;&nbsp;foo bar</p>")
end
- it "should use markdown for non-legacy comments" do
+ it "uses markdown for non-legacy comments" do
comment = Factory.build(:comment, :content => "**foo**", :legacy => false)
- helper.format_comment(comment).strip.should == "<p><strong>foo</strong></p>"
+ helper.format_comment(comment).strip.should eq("<p><strong>foo</strong></p>")
end
- it "should add http protocol to url if it doesn't exist" do
- helper.fix_url("foo.com").should == "http://foo.com"
- helper.fix_url("http://foo.com").should == "http://foo.com"
- helper.fix_url("https://foo.com").should == "https://foo.com"
- helper.fix_url("javascript:foo").should == "http://javascript:foo"
+ it "adds http protocol to url if it doesn't exist" do
+ helper.fix_url("foo.com").should eq("http://foo.com")
+ helper.fix_url("http://foo.com").should eq("http://foo.com")
+ helper.fix_url("https://foo.com").should eq("https://foo.com")
+ helper.fix_url("javascript:foo").should eq("http://javascript:foo")
end
end
@@ -7,30 +7,30 @@ def format(text)
it "determines language based on file path" do
formatter = CodeFormatter.new("")
- formatter.language("unknown").should == "unknown"
- formatter.language("hello.rb").should == "ruby"
- formatter.language("hello.js").should == "java_script"
- formatter.language("hello.css").should == "css"
- formatter.language("hello.html.erb").should == "rhtml"
- formatter.language("hello.yml").should == "yaml"
- formatter.language("Gemfile").should == "ruby"
- formatter.language("app.rake").should == "ruby"
- formatter.language("foo.gemspec").should == "ruby"
- formatter.language("rails console").should == "ruby"
- formatter.language("hello.js.rjs").should == "rjs"
- formatter.language("hello.scss").should == "css"
+ formatter.language("unknown").should eq("unknown")
+ formatter.language("hello.rb").should eq("ruby")
+ formatter.language("hello.js").should eq("java_script")
+ formatter.language("hello.css").should eq("css")
+ formatter.language("hello.html.erb").should eq("rhtml")
+ formatter.language("hello.yml").should eq("yaml")
+ formatter.language("Gemfile").should eq("ruby")
+ formatter.language("app.rake").should eq("ruby")
+ formatter.language("foo.gemspec").should eq("ruby")
+ formatter.language("rails console").should eq("ruby")
+ formatter.language("hello.js.rjs").should eq("rjs")
+ formatter.language("hello.scss").should eq("css")
end
it "converts to markdown" do
- format("hello **world**").strip.should == "<p>hello <strong>world</strong></p>"
+ format("hello **world**").strip.should eq("<p>hello <strong>world</strong></p>")
end
it "hard wraps return statements" do
- format("hello\nworld").strip.should == "<p>hello<br>\nworld</p>"
+ format("hello\nworld").strip.should eq("<p>hello<br>\nworld</p>")
end
it "autolinks a url" do
- format("http://www.example.com/").strip.should == '<p><a href="http://www.example.com/">http://www.example.com/</a></p>'
+ format("http://www.example.com/").strip.should eq('<p><a href="http://www.example.com/">http://www.example.com/</a></p>')
end
it "formats code block" do
@@ -44,6 +44,6 @@ def format(text)
end
it "does not allow html" do
- format("<img>").strip.should == ""
+ format("<img>").strip.should eq("")
end
end
@@ -2,29 +2,29 @@
require "ostruct"
describe Comment do
- it "should validate the presence of episode_id and content" do
+ it "validates the presence of episode_id and content" do
comment = Comment.new
%w[episode_id content].each do |attr|
comment.should have(1).error_on(attr)
end
end
- it "should set request based attributes" do
+ it "sets request based attributes" do
comment = Factory.build(:comment, :site_url => 'example.com')
comment.request = OpenStruct.new(:remote_ip => 'ip', :env => { 'HTTP_USER_AGENT' => 'agent', 'HTTP_REFERER' => 'referrer' })
- comment.user_ip.should == 'ip'
- comment.user_agent.should == 'agent'
- comment.referrer.should == 'referrer'
+ comment.user_ip.should eq('ip')
+ comment.user_agent.should eq('agent')
+ comment.referrer.should eq('referrer')
end
- it "should sort recent comments in descending order by created_at time" do
+ it "sorts recent comments in descending order by created_at time" do
Comment.delete_all
c1 = Factory(:comment, :created_at => 2.weeks.ago)
c2 = Factory(:comment, :created_at => Time.now)
- Comment.recent.should == [c2, c1]
+ Comment.recent.should eq([c2, c1])
end
- it "should notify owners of all previous commenters except self" do
+ it "notifies owners of all previous commenters except self" do
c1 = Factory(:comment)
c2a = Factory(:comment, :parent => c1)
c2b = Factory(:comment, :parent => c1)
@@ -34,7 +34,7 @@
last_email.to.should include(c1.user.email)
end
- it "should not notify user when user does not want email" do
+ it "does not notify user when user does not want email" do
c1 = Factory(:comment, :user => nil)
c2 = Factory(:comment, :parent => c2, :user => Factory(:user, :email_on_reply => false))
c3 = Factory(:comment, :parent => c2, :user => Factory(:user, :email => ""))
@@ -1,67 +1,67 @@
require "spec_helper"
describe Episode do
- it "should find published" do
+ it "finds published" do
a = Factory(:episode, :published_at => 2.weeks.ago)
b = Factory(:episode, :published_at => 2.weeks.from_now)
Episode.published.should include(a)
Episode.published.should_not include(b)
end
- it "should find unpublished" do
+ it "finds unpublished" do
a = Factory(:episode, :published_at => 2.weeks.ago)
b = Factory(:episode, :published_at => 2.weeks.from_now)
Episode.unpublished.should include(b)
Episode.unpublished.should_not include(a)
end
- it "should sort recent episodes in descending order" do
+ it "sorts recent episodes in descending order" do
Episode.delete_all
e1 = Factory(:episode, :position => 1)
e2 = Factory(:episode, :position => 2)
- Episode.recent.should == [e2, e1]
+ Episode.recent.should eq([e2, e1])
end
- it "should assign tags to episodes" do
+ it "assigns tags to episodes" do
episode = Factory(:episode, :tag_names => 'foo bar')
- episode.tags.map(&:name).should == %w[foo bar]
- episode.tag_names.should == 'foo bar'
+ episode.tags.map(&:name).should eq(%w[foo bar])
+ episode.tag_names.should eq('foo bar')
end
- it "should require publication date and name" do
+ it "requires publication date and name" do
episode = Episode.new
episode.should have(1).error_on(:published_at)
episode.should have(1).error_on(:name)
end
- it "should automatically generate permalink when creating episode" do
+ it "automatically generates permalink when creating episode" do
episode = Factory(:episode, :name => ' Hello_ *World* 2.1. ')
- episode.permalink.should == 'hello-world-2-1'
+ episode.permalink.should eq('hello-world-2-1')
end
- it "should include position and permalink in to_param" do
+ it "includes position and permalink in to_param" do
episode = Factory(:episode, :name => 'Foo Bar')
- episode.to_param.should == "#{episode.position}-foo-bar"
+ episode.to_param.should eq("#{episode.position}-foo-bar")
end
- it "should translate single digit seconds into duration with minutes" do
- Episode.new(:seconds => 60*8+3).duration.should == '8:03'
+ it "translates single digit seconds into duration with minutes" do
+ Episode.new(:seconds => 60*8+3).duration.should eq('8:03')
end
- it "should translate double digit seconds into duration with minutes" do
- Episode.new(:seconds => 60*8+12).duration.should == '8:12'
+ it "translates double digit seconds into duration with minutes" do
+ Episode.new(:seconds => 60*8+12).duration.should eq('8:12')
end
- it "should return nil for duration if seconds aren't set" do
+ it "returns nil for duration if seconds aren't set" do
Episode.new(:seconds => nil).duration.should be_nil
end
- it "should parse duration into seconds" do
- Episode.new(:duration => '10:03').seconds.should == 603
+ it "parses duration into seconds" do
+ Episode.new(:duration => '10:03').seconds.should eq(603)
Episode.new(:duration => '').seconds.should be_nil
end
- it "should know if it's the last published episode" do
+ it "knows if it's the last published episode" do
a = Factory(:episode, :published_at => 2.weeks.ago)
b = Factory(:episode, :published_at => 1.week.ago)
c = Factory(:episode, :published_at => 2.weeks.from_now)
@@ -73,22 +73,22 @@
it "has media.railscasts.com asset url" do
episode = Factory(:episode, :name => "Hello world")
episode.position = 23
- episode.asset_url("videos").should == "http://media.railscasts.com/assets/episodes/videos/023-hello-world"
- episode.asset_url("videos", "mp4").should == "http://media.railscasts.com/assets/episodes/videos/023-hello-world.mp4"
+ episode.asset_url("videos").should eq("http://media.railscasts.com/assets/episodes/videos/023-hello-world")
+ episode.asset_url("videos", "mp4").should eq("http://media.railscasts.com/assets/episodes/videos/023-hello-world.mp4")
end
it "has files with file sizes" do
episode = Factory(:episode, :name => "Hello world", :file_sizes => {"zip" => "12345"})
- episode.files[0][:name].should == "source code"
- episode.files.map { |f| f[:name] }.should == ["source code", "mp4", "m4v", "webm", "ogv"]
- episode.files.map { |f| f[:info] }.should == ["Project Files in Zip", "Full Size H.264 Video", "Smaller H.264 Video", "Full Size VP8 Video", "Full Size Theora Video"]
+ episode.files[0][:name].should eq("source code")
+ episode.files.map { |f| f[:name] }.should eq(["source code", "mp4", "m4v", "webm", "ogv"])
+ episode.files.map { |f| f[:info] }.should eq(["Project Files in Zip", "Full Size H.264 Video", "Smaller H.264 Video", "Full Size VP8 Video", "Full Size Theora Video"])
episode.files[0][:url].should include("http://media.railscasts.com/assets/episodes/sources/")
- episode.files[0][:size].should == 12345
+ episode.files[0][:size].should eq(12345)
end
it "sets file size to zero when unknown" do
episode = Factory(:episode, :name => "Hello world", :file_sizes => nil)
- episode.files[0][:size].should == 0
+ episode.files[0][:size].should eq(0)
end
it "loads the file sizes for each file" do
@@ -99,19 +99,19 @@
end
FakeWeb.register_uri(:head, "http://media.railscasts.com/assets/episodes/sources/042-hello-world.zip", :content_length => 4)
episode.load_file_sizes
- episode.file_sizes.should == {
+ episode.file_sizes.should eq(
"mp4" => "0",
"m4v" => "1",
"webm" => "2",
"ogv" => "3",
- "zip" => "4",
- }
+ "zip" => "4"
+ )
end
- it "should return nil as file size when response is not 200" do
+ it "returns nil as file size when response is not 200" do
FakeWeb.register_uri(:head, "http://example.com/foo", :content_length => "123", :status => ["404", "Not Found"])
episode = Factory.build(:episode)
- episode.fetch_file_size("http://example.com/foo").should == nil
+ episode.fetch_file_size("http://example.com/foo").should eq(nil)
end
it "has a full name which includes position" do
@@ -135,17 +135,17 @@
APP_CONFIG['thinking_sphinx'] = false
end
- it "should look in name, description, and notes" do
+ it "looks in name, description, and notes" do
e1 = Factory(:episode, :name => 'foo', :description => 'bar', :notes => 'baz', :published_at => 2.weeks.ago)
e2 = Factory(:episode, :name => 'foo test bar', :description => 'baz', :published_at => 2.weeks.ago)
e3 = Factory(:episode, :name => 'foo', :published_at => 2.weeks.ago)
- Episode.search_published('foo bar baz').should == [e1, e2]
+ Episode.search_published('foo bar baz').should eq([e1, e2])
end
- it "should not find unpublished" do
+ it "does not find unpublished" do
e1 = Factory(:episode, :name => 'foo', :published_at => 2.weeks.ago)
e2 = Factory(:episode, :name => 'foo', :published_at => 2.weeks.from_now)
- Episode.search_published('foo').should == [e1]
+ Episode.search_published('foo').should eq([e1])
end
end
end
View
@@ -1,11 +1,11 @@
require "spec_helper"
describe Tag do
- it "should find or create tags with names" do
+ it "finds or creates tags with names" do
Tag.delete_all
Tag.create!(:name => 'foo')
tags = Tag.with_names(['foo', 'bar'])
tags.should have(2).records
- Tag.find(:all).should == tags
+ Tag.find(:all).should eq(tags)
end
end
@@ -5,7 +5,7 @@
@tagging = Tagging.new
end
- it "should be valid" do
+ it "is valid" do
@tagging.should be_valid
end
end
View
@@ -1,29 +1,29 @@
require "spec_helper"
describe User do
- it "should create unique token when saving" do
+ it "creates unique token when saving" do
User.create!.token.should_not == User.create!.token
end
- it "should create from omniauth hash" do
+ it "creates from omniauth hash" do
omniauth = {"provider" => "github", "uid" => "123", "user_info" => {}, "extra" => {"user_hash" => {}}}
omniauth["user_info"]["email"] = "foo@example.com"
omniauth["user_info"]["name"] = "Bar"
omniauth["user_info"]["nickname"] = "foo"
omniauth["user_info"]["urls"] = {"GitHub" => "githubsite", "Blog" => "customsite"}
omniauth["extra"]["user_hash"]["gravatar_id"] = "avatar"
user = User.create_from_omniauth(omniauth)
- user.email.should == "foo@example.com"
- user.github_uid.should == "123"
- user.github_username.should == "foo"
- user.name.should == "Bar"
- user.gravatar_token.should == "avatar"
- user.site_url.should == "customsite"
+ user.email.should eq("foo@example.com")
+ user.github_uid.should eq("123")
+ user.github_username.should eq("foo")
+ user.name.should eq("Bar")
+ user.gravatar_token.should eq("avatar")
+ user.site_url.should eq("customsite")
user.email_on_reply.should be_true
user
end
- it "should generate persistant unsubscribe_token" do
+ it "generates persistant unsubscribe_token" do
user = Factory(:user)
user.unsubscribe_token.should be_nil
token = user.generated_unsubscribe_token
Oops, something went wrong.

0 comments on commit 952aafb

Please sign in to comment.