Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

End of Chapter 4

Added RSpec, Guard, Spork and Growl + Growlnotifier.
  • Loading branch information...
commit 3fdefdab49ce19d165ddd31e338452f17da14027 1 parent 8fb9e68
Simone Vittori authored
1  .rspec
View
@@ -1 +1,2 @@
--color
+--drb
16 Gemfile
View
@@ -9,11 +9,11 @@ gem 'bootstrap-will_paginate', '0.0.6'
gem 'jquery-rails', '2.0.2'
group :development, :test do
- gem 'sqlite3', '1.3.5'
+ # gem 'sqlite3', '1.3.5'
gem 'rspec-rails', '2.11.0'
- # gem 'guard-rspec', '1.2.1'
- # gem 'guard-spork', '1.2.0'
- # gem 'spork', '0.9.2'
+ gem 'guard-rspec', '1.2.1'
+ gem 'guard-spork', '1.2.0'
+ gem 'spork', '0.9.2'
end
# Gems used only for assets and not required
@@ -30,10 +30,10 @@ group :test do
gem 'cucumber-rails', '1.2.1', :require => false
gem 'database_cleaner', '0.7.0'
# gem 'launchy', '2.1.0'
- # gem 'rb-fsevent', '0.9.1', :require => false
- # gem 'growl', '1.0.3'
+ gem 'rb-fsevent', '0.9.1', :require => false
+ gem 'growl', '1.0.3'
end
-group :production do
+# group :production do
gem 'pg', '0.12.2'
-end
+# end
32 Gemfile.lock
View
@@ -44,6 +44,7 @@ GEM
xpath (~> 0.1.4)
childprocess (0.3.6)
ffi (~> 1.0, >= 1.0.6)
+ coderay (1.0.8)
coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
railties (~> 3.2.0)
@@ -75,6 +76,19 @@ GEM
ffi (1.2.0)
gherkin (2.11.5)
json (>= 1.4.6)
+ growl (1.0.3)
+ guard (1.5.4)
+ listen (>= 0.4.2)
+ lumberjack (>= 1.0.2)
+ pry (>= 0.9.10)
+ thor (>= 0.14.6)
+ guard-rspec (1.2.1)
+ guard (>= 1.1)
+ guard-spork (1.2.0)
+ childprocess
+ guard (>= 1.1)
+ spork (>= 0.8.4)
+ sys-proctable
hike (1.2.1)
i18n (0.6.1)
journey (1.0.4)
@@ -85,15 +99,22 @@ GEM
libwebsocket (0.1.7.1)
addressable
websocket
+ listen (0.6.0)
+ lumberjack (1.0.2)
mail (2.4.4)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
+ method_source (0.8.1)
mime-types (1.19)
multi_json (1.4.0)
nokogiri (1.5.5)
pg (0.12.2)
polyglot (0.3.3)
+ pry (0.9.10)
+ coderay (~> 1.0.5)
+ method_source (~> 0.8)
+ slop (~> 3.3.1)
rack (1.4.1)
rack-cache (1.2)
rack (>= 0.4)
@@ -117,6 +138,7 @@ GEM
rdoc (~> 3.4)
thor (>= 0.14.6, < 2.0)
rake (10.0.2)
+ rb-fsevent (0.9.1)
rdoc (3.12)
json (~> 1.4)
rspec (2.11.0)
@@ -143,12 +165,14 @@ GEM
libwebsocket (~> 0.1.3)
multi_json (~> 1.0)
rubyzip
+ slop (3.3.3)
+ spork (0.9.2)
sprockets (2.2.2)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
- sqlite3 (1.3.5)
+ sys-proctable (0.9.2)
thor (0.16.0)
tilt (1.3.3)
treetop (1.4.12)
@@ -176,11 +200,15 @@ DEPENDENCIES
database_cleaner (= 0.7.0)
factory_girl_rails (= 4.1.0)
faker (= 1.0.1)
+ growl (= 1.0.3)
+ guard-rspec (= 1.2.1)
+ guard-spork (= 1.2.0)
jquery-rails (= 2.0.2)
pg (= 0.12.2)
rails (= 3.2.9)
+ rb-fsevent (= 0.9.1)
rspec-rails (= 2.11.0)
sass-rails (= 3.2.5)
- sqlite3 (= 1.3.5)
+ spork (= 0.9.2)
uglifier (= 1.2.3)
will_paginate (= 3.0.3)
56 Guardfile
View
@@ -0,0 +1,56 @@
+# More info at https://github.com/guard/guard#readme
+
+require 'active_support/core_ext'
+
+
+guard 'spork', :cucumber_env => { 'RAILS_ENV' => 'test' }, :rspec_env => { 'RAILS_ENV' => 'test' } do
+ watch('config/application.rb')
+ watch('config/environment.rb')
+ watch('config/environments/test.rb')
+ watch(%r{^config/initializers/.+\.rb$})
+ watch('Gemfile')
+ watch('Gemfile.lock')
+ watch('spec/spec_helper.rb') { :rspec }
+ watch('test/test_helper.rb') { :test_unit }
+ watch(%r{features/support/}) { :cucumber }
+ watch('spec/support/')
+end
+
+
+guard 'rspec', version: 2, all_after_pass: false, cli: '--drb' do
+ watch(%r{^spec/.+_spec\.rb$})
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
+ watch('spec/spec_helper.rb') { "spec" }
+
+ # Rails example
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
+ watch('config/routes.rb') { "spec/routing" }
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
+
+ # Capybara request specs
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
+
+ # Turnip features and steps
+ watch(%r{^spec/acceptance/(.+)\.feature$})
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
+
+
+ # added from ruby on rails tutorial
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) do |m|
+ ["spec/routing/#{m[1]}_routing_spec.rb",
+ "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb",
+ "spec/acceptance/#{m[1]}_spec.rb",
+ (m[1][/_pages/] ? "spec/requests/#{m[1]}_spec.rb" :
+ "spec/requests/#{m[1].singularize}_pages_spec.rb")]
+ end
+ watch(%r{^app/views/(.+)/}) do |m|
+ (m[1][/_pages/] ? "spec/requests/#{m[1]}_spec.rb" :
+ "spec/requests/#{m[1].singularize}_pages_spec.rb")
+ end
+
+
+end
+
3  app/controllers/static_pages_controller.rb
View
@@ -8,4 +8,7 @@ def help
def about
end
+ def contact
+ end
+
end
12 app/views/static_pages/about.html.erb
View
@@ -1,10 +1,2 @@
-<!doctype html>
-<html lang="en">
-<head>
- <meta charset="UTF-8">
- <title>About Us | Ruby on Rails Tutorial Sample App</title>
-</head>
-<body>
- <h1>About Us</h1>
-</body>
-</html>
+<% provide(:title, 'About Us') %>
+<h1>About Us</h1>
6 app/views/static_pages/contact.html.erb
View
@@ -0,0 +1,6 @@
+<% provide(:title, 'Contact Us') %>
+<h1><%= yield(:title) %></h1>
+<p>
+ Contact Ruby on Rails Tutorial about the sample app at the
+ <a href="http://railstutorial.org/contact">contact page</a>.
+</p>
28 config/database.yml
View
@@ -1,25 +1,9 @@
-# SQLite version 3.x
-# gem install sqlite3
-#
-# Ensure the SQLite 3 gem is defined in your Gemfile
-# gem 'sqlite3'
development:
- adapter: sqlite3
- database: db/development.sqlite3
- pool: 5
- timeout: 5000
+ adapter: postgresql
+ database: sample_app_dev
+ host: localhost
-# Warning: The database defined as "test" will be erased and
-# re-generated from your development database when you run "rake".
-# Do not set this db to the same as development or production.
test:
- adapter: sqlite3
- database: db/test.sqlite3
- pool: 5
- timeout: 5000
-
-production:
- adapter: sqlite3
- database: db/production.sqlite3
- pool: 5
- timeout: 5000
+ adapter: postgresql
+ database: sample_app_test
+ host: localhost
1  config/routes.rb
View
@@ -2,6 +2,7 @@
get "static_pages/home"
get "static_pages/help"
get "static_pages/about"
+ get "static_pages/contact"
# The priority is based upon order of creation:
# first created -> highest priority.
16 db/schema.rb
View
@@ -0,0 +1,16 @@
+# encoding: UTF-8
+# This file is auto-generated from the current state of the database. Instead
+# of editing this file, please use the migrations feature of Active Record to
+# incrementally modify your database, and then regenerate this schema definition.
+#
+# Note that this schema.rb definition is the authoritative source for your
+# database schema. If you need to create the application database on another
+# system, you should be using db:schema:load, not running all the migrations
+# from scratch. The latter is a flawed and unsustainable approach (the more migrations
+# you'll amass, the slower it'll run and the greater likelihood for issues).
+#
+# It's strongly recommended to check this file into your version control system.
+
+ActiveRecord::Schema.define(:version => 0) do
+
+end
19 spec/requests/static_pages_spec.rb
View
@@ -1,6 +1,9 @@
require 'spec_helper'
describe "StaticPages" do
+
+ let(:base_title) { "Ruby on Rails Tutorial Sample App" }
+
describe "Home page" do
it "should have the content 'Home page'" do
visit '/static_pages/home'
@@ -8,7 +11,7 @@
end
it "should have the right title" do
visit '/static_pages/home'
- page.should have_selector('title', text: "Home | Ruby on Rails Tutorial Sample App")
+ page.should have_selector('title', text: "Home | #{base_title}")
end
end
describe "Help page" do
@@ -18,7 +21,7 @@
end
it "should have the right title" do
visit '/static_pages/help'
- page.should have_selector('title', text: "Help | Ruby on Rails Tutorial Sample App")
+ page.should have_selector('title', text: "Help | #{base_title}")
end
end
describe "About page" do
@@ -28,7 +31,17 @@
end
it "should have the right title" do
visit '/static_pages/about'
- page.should have_selector('title', text: "About Us | Ruby on Rails Tutorial Sample App")
+ page.should have_selector('title', text: "About Us | #{base_title}")
end
end
+ describe "Contact page" do
+ it "should have the content 'Contact Us'" do
+ visit '/static_pages/contact'
+ page.should have_selector('h1', text: 'Contact Us')
+ end
+ it "should have the right title" do
+ visit '/static_pages/contact'
+ page.should have_selector('title', text: "Contact Us | #{base_title}")
+ end
+ end
end
84 spec/spec_helper.rb
View
@@ -1,3 +1,87 @@
+require 'rubygems'
+require 'spork'
+#uncomment the following line to use spork with the debugger
+#require 'spork/ext/ruby-debug'
+
+Spork.prefork do
+ # Loading more in this block will cause your tests to run faster. However,
+ # if you change any configuration or code from libraries loaded here, you'll
+ # need to restart spork for it take effect.
+
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
+ ENV["RAILS_ENV"] ||= 'test'
+ require File.expand_path("../../config/environment", __FILE__)
+ require 'rspec/rails'
+ require 'rspec/autorun'
+
+ # Requires supporting ruby files with custom matchers and macros, etc,
+ # in spec/support/ and its subdirectories.
+ Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
+
+ RSpec.configure do |config|
+ # == Mock Framework
+ #
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
+ #
+ # config.mock_with :mocha
+ # config.mock_with :flexmock
+ # config.mock_with :rr
+ config.mock_with :rspec
+
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
+
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
+ # examples within a transaction, remove the following line or assign false
+ # instead of true.
+ config.use_transactional_fixtures = true
+
+ # If true, the base class of anonymous controllers will be inferred
+ # automatically. This will be the default behavior in future versions of
+ # rspec-rails.
+ config.infer_base_class_for_anonymous_controllers = false
+ end
+
+
+end
+
+Spork.each_run do
+ # This code will be run each time you run your specs.
+
+end
+
+# --- Instructions ---
+# Sort the contents of this file into a Spork.prefork and a Spork.each_run
+# block.
+#
+# The Spork.prefork block is run only once when the spork server is started.
+# You typically want to place most of your (slow) initializer code in here, in
+# particular, require'ing any 3rd-party gems that you don't normally modify
+# during development.
+#
+# The Spork.each_run block is run each time you run your specs. In case you
+# need to load files that tend to change during development, require them here.
+# With Rails, your application modules are loaded automatically, so sometimes
+# this block can remain empty.
+#
+# Note: You can modify files loaded *from* the Spork.each_run block without
+# restarting the spork server. However, this file itself will not be reloaded,
+# so if you change any of the code inside the each_run block, you still need to
+# restart the server. In general, if you have non-trivial code in this file,
+# it's advisable to move it into a separate file so you can easily edit it
+# without restarting spork. (For example, with RSpec, you could move
+# non-trivial code into a file spec/support/my_helper.rb, making sure that the
+# spec/support/* files are require'd from inside the each_run block.)
+#
+# Any code that is left outside the two blocks will be run during preforking
+# *and* during each_run -- that's probably not what you want.
+#
+# These instructions should self-destruct in 10 seconds. If they don't, feel
+# free to delete them.
+
+
+
+
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
Please sign in to comment.
Something went wrong with that request. Please try again.