Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

spec cleaning

  • Loading branch information...
commit a44b1ebc0112d5ed349696d3345edc80e88b0f2e 1 parent 4779a1f
@yaf yaf authored
View
30 spec/controllers/articles_controller_spec.rb
@@ -57,11 +57,11 @@
it 'should have a canonical url' do
response.should have_selector('head>link[href="http://test.host/"]')
end
-
+
it 'should have googd title' do
response.should have_selector('title', :content => "test blog | test subtitles")
end
-
+
it 'should have a custom tracking field' do
response.should have_selector('head>script[src="foo.js"]')
end
@@ -100,7 +100,7 @@
it 'should have a canonical url' do
response.should have_selector('head>link[href="http://test.host/search/a"]')
end
-
+
it 'should have a good title' do
response.should have_selector('title', :content => "Results for a | test blog")
end
@@ -137,7 +137,7 @@
response.should render_template('articles/error')
assigns[:articles].should be_empty
end
-
+
end
describe '#livesearch action' do
@@ -207,11 +207,11 @@
it 'should have a canonical url' do
response.should have_selector('head>link[href="http://test.host/2004/4/"]')
end
-
+
it 'should have a good title' do
response.should have_selector('title', :content => "Archives for test blog")
end
-
+
it 'should have a custom tracking field' do
response.should have_selector('head>script[src="foo.js"]')
end
@@ -329,11 +329,19 @@
@article = Factory(:article)
end
- with_each_theme do |theme, view_path|
- it "should render template #{view_path}/articles/read" do
- @blog.theme = theme if theme
- get :preview, :id => @article.id
- response.should render_template('articles/read')
+ [nil, 'theme', 'view_path'].each do |theme|
+ describe theme ? "with theme #{theme}" : "without a theme" do
+ view_path = ''
+ Dir.new(File.join(::Rails.root.to_s, "themes")).each do |theme|
+ next if theme =~ /\.\.?/
+ view_path = "#{::Rails.root.to_s}/themes/#{theme}/views"
+
+ it "should render template #{view_path}/articles/read" do
+ @blog.theme = theme if theme
+ get :preview, :id => @article.id
+ response.should render_template('articles/read')
+ end
+ end
end
end
View
13 spec/spec_helper.rb
@@ -90,19 +90,6 @@ def stub_full_article(time=Time.now)
a
end
-# test standard view and all themes
-def with_each_theme
- yield nil, ""
- Dir.new(File.join(::Rails.root.to_s, "themes")).each do |theme|
- next if theme =~ /\.\.?/
- view_path = "#{::Rails.root.to_s}/themes/#{theme}/views"
- if File.exists?("#{::Rails.root.to_s}/themes/#{theme}/helpers/theme_helper.rb")
- require "#{::Rails.root.to_s}/themes/#{theme}/helpers/theme_helper.rb"
- end
- yield theme, view_path
- end
-end
-
# This test now has optional support for validating the generated RSS feeds.
# Since Ruby doesn't have a RSS/Atom validator, I'm using the Python source
# for http://feedvalidator.org and calling it via 'system'.
View
141 spec/views/articles/index_spec.rb
@@ -1,85 +1,94 @@
require 'spec_helper'
describe "articles/index.html.erb" do
-with_each_theme do |theme, view_path|
- describe theme ? "with theme #{theme}" : "without a theme" do
- before(:each) do
- @controller.view_paths.unshift(view_path) if theme
- end
- context "normally" do
+ [nil, 'theme', 'view_path'].each do |theme|
+ describe theme ? "with theme #{theme}" : "without a theme" do
before(:each) do
- Factory(:blog)
- 2.times {Factory(:article, :body => 'body')}
- @controller.action_name = "index"
- @controller.request.path_parameters["controller"] = "articles"
- assign(:articles, Article.paginate(:all, :page => 1, :per_page => 4))
-
- render
- end
-
- subject { rendered }
-
- it "should not have too many paragraph marks around body" do
- should have_selector("p", :content => "body")
- should_not have_selector("p>p", :content => "body")
- end
-
- it "should not have div nested inside p" do
- should_not have_selector("p>div")
- end
-
- it "should not have extra escaped html" do
- should_not =~ /</
- should_not =~ />/
- should_not =~ /&/
+ view_path = ''
+ Dir.new(File.join(::Rails.root.to_s, "themes")).each do |theme|
+ next if theme =~ /\.\.?/
+ view_path = "#{::Rails.root.to_s}/themes/#{theme}/views"
+ if File.exists?("#{::Rails.root.to_s}/themes/#{theme}/helpers/theme_helper.rb")
+ require "#{::Rails.root.to_s}/themes/#{theme}/helpers/theme_helper.rb"
+ end
+ end
+ @controller.view_paths.unshift(view_path) if theme
end
- end
-
- context "without search, on page 2" do
- before(:each) do
- Factory(:blog)
- 3.times { Factory(:article) }
- @controller.action_name = "index"
- @controller.request.path_parameters["controller"] = "articles"
- assign(:articles, Article.paginate(:all, :page => 2, :per_page => 2))
- render
+ context "normally" do
+ before(:each) do
+ Factory(:blog)
+ 2.times {Factory(:article, :body => 'body')}
+ @controller.action_name = "index"
+ @controller.request.path_parameters["controller"] = "articles"
+ assign(:articles, Article.paginate(:all, :page => 1, :per_page => 4))
+
+ render
+ end
+
+ subject { rendered }
+
+ it "should not have too many paragraph marks around body" do
+ should have_selector("p", :content => "body")
+ should_not have_selector("p>p", :content => "body")
+ end
+
+ it "should not have div nested inside p" do
+ should_not have_selector("p>div")
+ end
+
+ it "should not have extra escaped html" do
+ should_not =~ /</
+ should_not =~ />/
+ should_not =~ /&/
+ end
end
- subject { rendered }
+ context "without search, on page 2" do
+ before(:each) do
+ Factory(:blog)
+ 3.times { Factory(:article) }
+ @controller.action_name = "index"
+ @controller.request.path_parameters["controller"] = "articles"
+ assign(:articles, Article.paginate(:all, :page => 2, :per_page => 2))
- it "should not have pagination link to page 2" do
- should_not have_selector("a", :href => "/page/2")
- end
+ render
+ end
- it "should have pagination link to page 1" do
- should have_selector("a", :href=> "/page/1")
- end
- end
+ subject { rendered }
- context "when on page 2 of search" do
- before(:each) do
- Factory(:blog)
- 3.times {Factory(:article, :body => 'body')}
- @controller.action_name = "search"
- @controller.request.path_parameters["controller"] = "articles"
- params[:q] = "body"
- params[:page] = 2
- params[:action] = 'search'
- assign(:articles, Blog.default.articles_matching(params[:q], :page => 2, :per_page => 2))
-
- render
- end
+ it "should not have pagination link to page 2" do
+ should_not have_selector("a", :href => "/page/2")
+ end
- it "should not have pagination link to search page 2" do
- rendered.should_not have_selector("a", :href => "/search/body/page/2")
+ it "should have pagination link to page 1" do
+ should have_selector("a", :href=> "/page/1")
+ end
end
- it "should have pagination link to search page 1" do
- rendered.should have_selector("a", :href => "/search/body/page/1")
+ context "when on page 2 of search" do
+ before(:each) do
+ Factory(:blog)
+ 3.times {Factory(:article, :body => 'body')}
+ @controller.action_name = "search"
+ @controller.request.path_parameters["controller"] = "articles"
+ params[:q] = "body"
+ params[:page] = 2
+ params[:action] = 'search'
+ assign(:articles, Blog.default.articles_matching(params[:q], :page => 2, :per_page => 2))
+
+ render
+ end
+
+ it "should not have pagination link to search page 2" do
+ rendered.should_not have_selector("a", :href => "/search/body/page/2")
+ end
+
+ it "should have pagination link to search page 1" do
+ rendered.should have_selector("a", :href => "/search/body/page/1")
+ end
end
end
end
end
-end
View
64 spec/views/articles/read_spec.rb
@@ -1,9 +1,18 @@
require 'spec_helper'
describe "articles/read.html.erb" do
- with_each_theme do |theme, view_path|
+ [nil, 'theme', 'view_path'].each do |theme|
describe theme ? "with theme #{theme}" : "without a theme" do
before(:each) do
+ view_path = ''
+ Dir.new(File.join(::Rails.root.to_s, "themes")).each do |theme|
+ next if theme =~ /\.\.?/
+ view_path = "#{::Rails.root.to_s}/themes/#{theme}/views"
+ if File.exists?("#{::Rails.root.to_s}/themes/#{theme}/helpers/theme_helper.rb")
+ require "#{::Rails.root.to_s}/themes/#{theme}/helpers/theme_helper.rb"
+ end
+ end
+
@controller.view_paths.unshift(view_path) if theme
# we do not want to test article links and such
@@ -14,53 +23,40 @@
view.stub(:display_date_and_time) {|dt| dt.to_s}
blog = stub_default_blog
- blog.comment_text_filter = "textile"
+ blog.comment_text_filter = Factory.create(:textile).name
@controller.action_name = "redirect"
- article = stub_full_article(Time.now - 2.hours)
+ #article = stub_full_article(Time.now - 2.hours)
+ time = Time.now - 2.hours
+ article = Factory.create(:article, :published_at => time, :updated_at => time, :created_at => time, :text_filter => Factory.create(:textile))
article.body = 'body'
article.extended = 'extended content'
- @c1 = stub_model(Comment, :created_at => Time.now - 2.seconds, :body => 'Comment body _italic_ *bold*')
- @c2 = stub_model(Comment, :created_at => Time.now, :body => 'Hello foo@bar.com http://www.bar.com')
+ @c1 = Factory.create(:comment, :created_at => Time.now - 2.seconds, :body => 'Comment body _italic_ *bold*')
+ @c2 = Factory.create(:comment, :created_at => Time.now, :body => 'Hello foo@bar.com http://www.bar.com')
article.stub(:published_comments) { [@c1, @c2] }
- text_filter = Factory.build(:textile)
+ text_filter = Factory.create(:textile)
TextFilter.stub(:find_by_name) { text_filter }
assign(:article, article)
render
end
- it "should not have too many paragraph marks around body" do
- rendered.should have_selector("p", :content => "body")
- rendered.should_not have_selector("p>p", :content => "body")
- end
-
- it "should not have too many paragraph marks around extended contents" do
- rendered.should have_selector("p", :content => "extended content")
- rendered.should_not have_selector("p>p", :content => "extended content")
- end
-
- # FIXME: Move comment partial specs to their own spec file.
- it "should not have too many paragraph marks around comment contents" do
- rendered.should have_selector("p>em", :content => "italic")
- rendered.should have_selector("p>strong", :content => "bold")
- rendered.should_not have_selector("p>p>em", :content => "italic")
- end
-
- it "should automatically add links" do
- rendered.should have_selector("a", :href => "mailto:foo@bar.com",
- :content => "foo@bar.com")
- rendered.should have_selector("a", :href=>"http://www.bar.com",
- :content => "http://www.bar.com")
- end
-
- it "should show the comment creation times in the comment list" do
- rendered.should =~ /#{@c1.created_at.to_s}/
- rendered.should =~ /#{@c2.created_at.to_s}/
- end
+ subject { rendered }
+
+ it {should have_selector("p", :content => "body") }
+ it {should_not have_selector("p>p", :content => "body")}
+ it {should have_selector("p", :content => "extended content")}
+ it {should_not have_selector("p>p", :content => "extended content")}
+ it {should have_selector("p>em", :content => "italic")}
+ it {should have_selector("p>strong", :content => "bold")}
+ it {should_not have_selector("p>p>em", :content => "italic")}
+ it {should have_selector("a", :href => "mailto:foo@bar.com", :content => "foo@bar.com")}
+ it {should have_selector("a", :href=>"http://www.bar.com", :content => "http://www.bar.com")}
+ it {should =~ /#{@c1.created_at.to_s}/}
+ it {should =~ /#{@c2.created_at.to_s}/}
end
end
end
View
13 spec/views/layouts/default_spec.rb
@@ -7,12 +7,19 @@
assign(:auto_discovery_url_rss, "")
end
- with_each_theme do |theme, view_path|
+ [nil, 'theme', 'view_path'].each do |theme|
# FIXME: Add default.html.erb in base view dir.
next unless theme
-
describe theme ? "with theme #{theme}" : "without a theme" do
- before do
+ before(:each) do
+ view_path = ''
+ Dir.new(File.join(::Rails.root.to_s, "themes")).each do |theme|
+ next if theme =~ /\.\.?/
+ view_path = "#{::Rails.root.to_s}/themes/#{theme}/views"
+ if File.exists?("#{::Rails.root.to_s}/themes/#{theme}/helpers/theme_helper.rb")
+ require "#{::Rails.root.to_s}/themes/#{theme}/helpers/theme_helper.rb"
+ end
+ end
@controller.view_paths.unshift(view_path) if theme
end
Please sign in to comment.
Something went wrong with that request. Please try again.