Permalink
Browse files

Clean up syntax to follow styleguide

  • Loading branch information...
1 parent eea2907 commit 0fb4e94a7aa66703dc490811719b50d51103f983 @harlow harlow committed Oct 29, 2012
View
@@ -181,22 +181,25 @@ system, A/B test, and so on.
Testing
-------
-Just a suggestion, but you can test your pages using Shoulda pretty easily:
-
- class PagesControllerTest < ActionController::TestCase
- tests PagesController
+You can test your static pages using [RSpec](https://github.com/rspec/rspec-rails)
+and [shoulda-matchers](https://github.com/thoughtbot/shoulda-matchers):
+ # spec/controllers/pages_controller_spec.rb
+ describe PagesController, '#show' do
%w(earn_money screencast about contact).each do |page|
- context "on GET to /pages/#{page}" do
- setup { get :show, :id => page }
+ context 'on GET to /pages/#{page}' do
+ before do
+ get :show, :id => page
+ end
- should_respond_with :success
- should_render_template page
+ it { should respond_with(:success) }
+ it { should render_template(page) }
end
end
end
-If you're not using a custom PagesController be sure to test <code>HighVoltage::PagesController</code> instead.
+If you're not using a custom PagesController be sure to test
+`HighVoltage::PagesController` instead.
Enjoy!
@@ -219,4 +222,5 @@ The names and logos for thoughtbot are trademarks of thoughtbot, inc.
License
-------
-High Voltage is Copyright © 2009-2012 thoughtbot. It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
+High Voltage is Copyright © 2009-2012 thoughtbot. It is free software, and may
+be redistributed under the terms specified in the MIT-LICENSE file.
@@ -1,5 +1,3 @@
-require 'high_voltage/page_finder'
-
class HighVoltage::PagesController < ApplicationController
unloadable
layout Proc.new { |_| HighVoltage.layout }
@@ -1,7 +1,6 @@
require 'spec_helper'
describe AlternativeFinderController do
-
render_views
it 'renders the file from the alternative directory' do
@@ -28,15 +28,24 @@
end
it 'should raise a routing error for an invalid page' do
- lambda { get :show, :id => 'invalid' }.should raise_error(ActionController::RoutingError)
+ lambda {
+ get :show,
+ :id => 'invalid'
+ }.should raise_error(ActionController::RoutingError)
end
it 'should raise a routing error for a page in another directory' do
- lambda { get :show, :id => '../other/wrong' }.should raise_error(ActionController::RoutingError)
+ lambda {
+ get :show,
+ :id => '../other/wrong'
+ }.should raise_error(ActionController::RoutingError)
end
it 'should raise missing template error for valid page with invalid partial' do
- lambda { get :show, :id => 'exists_but_references_nonexistent_partial' }.should raise_error(ActionView::MissingTemplate)
+ lambda {
+ get :show,
+ :id => 'exists_but_references_nonexistent_partial'
+ }.should raise_error(ActionView::MissingTemplate)
end
end
@@ -1,32 +1,40 @@
require 'spec_helper'
describe SubclassedPagesController do
-
render_views
- describe "on GET to /subclassed_pages/also_exists" do
+ describe 'on GET to /subclassed_pages/also_exists' do
before { get :show, :id => 'also_exists' }
- it "should respond with success and render template" do
+ it 'should respond with success and render template' do
response.should be_success
response.should render_template('also_exists')
end
- it "should use the custom configured layout" do
- response.should_not render_template("layouts/application")
+ it 'should use the custom configured layout' do
+ response.should_not render_template('layouts/application')
response.should render_template('layouts/alternate')
end
end
- it "should raise a routing error for an invalid page" do
- lambda { get :show, :id => "invalid" }.should raise_error(ActionController::RoutingError)
+ it 'should raise a routing error for an invalid page' do
+ lambda {
+ get :show,
+ :id => 'invalid'
+ }.should raise_error(ActionController::RoutingError)
end
- it "should raise a routing error for a page in another directory" do
- lambda { get :show, :id => "../other/wrong" }.should raise_error(ActionController::RoutingError)
+ it 'should raise a routing error for a page in another directory' do
+ lambda {
+ get :show,
+ :id => '../other/wrong'
+ }.should raise_error(ActionController::RoutingError)
end
- it "should raise missing template error for valid page with invalid partial" do
- lambda { get :show, :id => "also_exists_but_references_nonexistent_partial" }.should raise_error(ActionView::MissingTemplate)
+ it 'should raise missing template error for valid page with invalid partial' do
+ lambda {
+ get :show,
+ :id => 'also_exists_but_references_nonexistent_partial'
+ }.should raise_error(ActionView::MissingTemplate)
end
end
@@ -1,24 +1,23 @@
require 'spec_helper'
-require 'high_voltage/page_finder'
describe HighVoltage::PageFinder do
it 'produces the name of an existing template' do
- find('existing').should == 'pages/existing'
+ find('existing').should eq 'pages/existing'
end
it 'produces the name of a nested template' do
- find('dir/nested').should == 'pages/dir/nested'
+ find('dir/nested').should eq 'pages/dir/nested'
end
it 'uses a custom content path' do
with_content_path('other_pages/') do
- find('also_exists').should == 'other_pages/also_exists'
+ find('also_exists').should eq 'other_pages/also_exists'
end
end
it 'exposes the content path' do
with_content_path('another_thing/') do
- page_finder.content_path.should == 'another_thing/'
+ page_finder.content_path.should eq 'another_thing/'
end
end
@@ -29,7 +28,7 @@ def page_name
end
end
- subclass.new('sweet page').page_name.should == 'the page is sweet page'
+ subclass.new('sweet page').page_name.should eq 'the page is sweet page'
end
private
@@ -1,7 +1,7 @@
require 'spec_helper'
describe HighVoltage do
- it "should be valid" do
+ it 'should be valid' do
HighVoltage.should be_a(Module)
end
-end
+end
@@ -1,9 +1,9 @@
require 'spec_helper'
-describe "Navigation" do
+describe 'Navigation' do
include Capybara::DSL
-
- it "should be a valid app" do
+
+ it 'should be a valid app' do
::Rails.application.should be_a(Dummy::Application)
end
end
@@ -15,27 +15,48 @@
end
it 'should recognize nested route' do
- assert_recognizes({:controller => 'high_voltage/pages', :action => 'show', :id => 'one/two'}, '/pages/one/two')
+ assert_recognizes(
+ {
+ :controller => 'high_voltage/pages',
+ :action => 'show',
+ :id => 'one/two'
+ },
+ '/pages/one/two'
+ )
end
it 'should recognize normal route' do
- assert_recognizes({:controller => 'high_voltage/pages', :action => 'show', :id => 'one'}, '/pages/one')
+ assert_recognizes(
+ {
+ :controller => 'high_voltage/pages',
+ :action => 'show',
+ :id => 'one'
+ },
+ '/pages/one'
+ )
end
it 'should recognize normal route with dots' do
- assert_recognizes({:controller => 'high_voltage/pages', :action => 'show', :id => 'one.two.three'}, '/pages/one.two.three')
+ assert_recognizes(
+ {
+ :controller => 'high_voltage/pages',
+ :action => 'show',
+ :id => 'one.two.three'
+ },
+ '/pages/one.two.three'
+ )
end
end
context 'using root routing configuration' do
- before(:all) do
- @original_route_drawer = HighVoltage.route_drawer
+ around do |example|
+ cached_high_voltage_route_drawer = HighVoltage.route_drawer
HighVoltage.route_drawer = HighVoltage::RouteDrawers::Root
Rails.application.reload_routes!
- end
- after(:all) do
- HighVoltage.route_drawer = @original_route_drawer
+ example.run
+
+ HighVoltage.route_drawer = cached_high_voltage_route_drawer
Rails.application.reload_routes!
end
@@ -53,14 +74,14 @@
end
context 'using a custom content_path' do
- before(:all) do
- @original_content_path = HighVoltage.content_path
+ around do |example|
+ cached_high_voltage_content_path = HighVoltage.content_path
HighVoltage.content_path = 'other_pages/'
Rails.application.reload_routes!
- end
- after(:all) do
- HighVoltage.content_path = @original_content_path
+ example.run
+
+ HighVoltage.content_path = cached_high_voltage_content_path
Rails.application.reload_routes!
end
@@ -77,15 +98,36 @@
end
it 'should recognize nested route' do
- assert_recognizes({:controller => 'high_voltage/pages', :action => 'show', :id => 'one/two'}, '/other_pages/one/two')
+ assert_recognizes(
+ {
+ :controller => 'high_voltage/pages',
+ :action => 'show',
+ :id => 'one/two'
+ },
+ '/other_pages/one/two'
+ )
end
it 'should recognize normal route' do
- assert_recognizes({:controller => 'high_voltage/pages', :action => 'show', :id => 'one'}, '/other_pages/one')
+ assert_recognizes(
+ {
+ :controller => 'high_voltage/pages',
+ :action => 'show',
+ :id => 'one'
+ },
+ '/other_pages/one'
+ )
end
it 'should recognize normal route with dots' do
- assert_recognizes({:controller => 'high_voltage/pages', :action => 'show', :id => 'one.two.three'}, '/other_pages/one.two.three')
+ assert_recognizes(
+ {
+ :controller => 'high_voltage/pages',
+ :action => 'show',
+ :id => 'one.two.three'
+ },
+ '/other_pages/one.two.three'
+ )
end
end
@@ -94,7 +136,9 @@
cached_high_voltage_routes = HighVoltage.routes
HighVoltage.routes = false
Rails.application.reload_routes!
+
example.run
+
HighVoltage.routes = cached_high_voltage_routes
Rails.application.reload_routes!
end
View
@@ -1,26 +1,18 @@
-# Configure Rails Envinronment
-ENV["RAILS_ENV"] = "test"
+ENV['RAILS_ENV'] = 'test'
require File.expand_path("../dummy/config/environment.rb", __FILE__)
-require "rails/test_help"
-require "rspec/rails"
+require 'rails/test_help'
+require 'rspec/rails'
+require 'capybara/rails'
Rails.backtrace_cleaner.remove_silencers!
-
-# Configure capybara for integration testing
-require "capybara/rails"
Capybara.default_driver = :rack_test
Capybara.default_selector = :css
-# Load support files
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
RSpec.configure do |config|
- # Remove this line if you don't want RSpec's should and should_not
- # methods or matchers
require 'rspec/expectations'
config.include RSpec::Matchers
-
- # == Mock Framework
config.mock_with :rspec
end

0 comments on commit 0fb4e94

Please sign in to comment.