Replace the ruby unit testing framework with rspec

Add watchr and spork to speed up the test run. Please note that spork
and watchr needs to start up separately. (See Gemfile for more
information)
This commit is contained in:
Aaron Mueller 2012-05-23 23:55:53 +02:00
parent e77aecfdab
commit 9ea67909cc
23 changed files with 108 additions and 86 deletions

1
.rspec Normal file
View file

@ -0,0 +1 @@
--colour --drb

19
.watchr Normal file
View file

@ -0,0 +1,19 @@
def run_spec(file)
unless File.exists?(file)
puts "#{file} does not exist"
return
end
puts "Running #{file}"
system "bundle exec rspec --format documentation #{file}"
puts "*"*72
end
watch("spec/.*/*_spec.rb") do |match|
run_spec(match[0])
end
watch("app/(.*/.*).rb") do |match|
run_spec %{spec/#{match[1]}_spec.rb}
end

11
Gemfile
View file

@ -1,6 +1,7 @@
source 'https://rubygems.org' source 'https://rubygems.org'
gem 'rails', '3.2.0' gem 'rails', '3.2.0'
gem 'jquery-rails'
# Bundle edge Rails instead: # Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git' # gem 'rails', :git => 'git://github.com/rails/rails.git'
@ -21,7 +22,15 @@ group :assets do
gem 'uglifier', '>= 1.0.3' gem 'uglifier', '>= 1.0.3'
end end
gem 'jquery-rails'
group :development, :test do
gem 'rspec-rails', '>= 2.7'
# To use it, run "spork" first and "watchr .watchr" in a second terminal
# to speed up the test runs.
gem 'watchr'
gem 'spork', '~> 0.9.0.rc'
end
# To use ActiveModel has_secure_password # To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0' # gem 'bcrypt-ruby', '~> 3.0.0'

View file

@ -38,6 +38,7 @@ GEM
execjs execjs
coffee-script-source (1.2.0) coffee-script-source (1.2.0)
curb (0.7.18) curb (0.7.18)
diff-lcs (1.1.3)
erubis (2.7.0) erubis (2.7.0)
execjs (1.3.0) execjs (1.3.0)
multi_json (~> 1.0) multi_json (~> 1.0)
@ -93,6 +94,19 @@ GEM
rake (0.9.2.2) rake (0.9.2.2)
rdoc (3.12) rdoc (3.12)
json (~> 1.4) json (~> 1.4)
rspec (2.10.0)
rspec-core (~> 2.10.0)
rspec-expectations (~> 2.10.0)
rspec-mocks (~> 2.10.0)
rspec-core (2.10.1)
rspec-expectations (2.10.0)
diff-lcs (~> 1.1.3)
rspec-mocks (2.10.1)
rspec-rails (2.10.1)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec (~> 2.10.0)
sass (3.1.15) sass (3.1.15)
sass-rails (3.2.5) sass-rails (3.2.5)
railties (~> 3.2.0) railties (~> 3.2.0)
@ -100,6 +114,7 @@ GEM
tilt (~> 1.3) tilt (~> 1.3)
sax-machine (0.0.20) sax-machine (0.0.20)
nokogiri (> 0.0.0) nokogiri (> 0.0.0)
spork (0.9.2)
sprockets (2.1.2) sprockets (2.1.2)
hike (~> 1.2) hike (~> 1.2)
rack (~> 1.0) rack (~> 1.0)
@ -114,6 +129,7 @@ GEM
uglifier (1.2.4) uglifier (1.2.4)
execjs (>= 0.3.0) execjs (>= 0.3.0)
multi_json (>= 1.0.2) multi_json (>= 1.0.2)
watchr (0.7)
PLATFORMS PLATFORMS
ruby ruby
@ -123,6 +139,9 @@ DEPENDENCIES
feedzirra feedzirra
jquery-rails jquery-rails
rails (= 3.2.0) rails (= 3.2.0)
rspec-rails (>= 2.7)
sass-rails (~> 3.2.3) sass-rails (~> 3.2.3)
spork (~> 0.9.0.rc)
sqlite3 sqlite3
uglifier (>= 1.0.3) uglifier (>= 1.0.3)
watchr

1
spec/feed_spec.rb Normal file
View file

@ -0,0 +1 @@

9
spec/item_spec.rb Normal file
View file

@ -0,0 +1,9 @@
require "spec_helper"
describe Item do
# TODO: start writing tests
it "can be instanciate" do
Item.new.should be_an_instance_of(Item)
end
end

8
spec/models/item_spec.rb Normal file
View file

@ -0,0 +1,8 @@
require "spec_helper"
describe Item do
it "can be instantiated" do
Item.new.should be_an_instance_of(Item)
end
end

41
spec/spec_helper.rb Normal file
View file

@ -0,0 +1,41 @@
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.
end
Spork.each_run do
# This code will be run each time you run your specs.
end
# 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'
# 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
end

View file

View file

@ -1,9 +0,0 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
one:
uri: MyString
title: MyString
two:
uri: MyString
title: MyString

View file

@ -1,15 +0,0 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
one:
title: MyString
url: MyString
author: MyString
content: MyText
published: 2012-04-07 18:52:40
two:
title: MyString
url: MyString
author: MyString
content: MyText
published: 2012-04-07 18:52:40

View file

@ -1,7 +0,0 @@
require 'test_helper'
class FeedsControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end
end

View file

@ -1,7 +0,0 @@
require 'test_helper'
class ItemsControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end
end

View file

@ -1,12 +0,0 @@
require 'test_helper'
require 'rails/performance_test_help'
class BrowsingTest < ActionDispatch::PerformanceTest
# Refer to the documentation for all available options
# self.profile_options = { :runs => 5, :metrics => [:wall_time, :memory]
# :output => 'tmp/performance', :formats => [:flat] }
def test_homepage
get '/'
end
end

View file

@ -1,13 +0,0 @@
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
#
# Note: You'll currently still have to declare fixtures explicitly in integration tests
# -- they do not yet inherit this setting
fixtures :all
# Add more helper methods to be used by all tests here...
end

View file

View file

@ -1,7 +0,0 @@
require 'test_helper'
class FeedTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

View file

@ -1,4 +0,0 @@
require 'test_helper'
class FeedHelperTest < ActionView::TestCase
end

View file

@ -1,4 +0,0 @@
require 'test_helper'
class ItemsHelperTest < ActionView::TestCase
end

View file

@ -1,7 +0,0 @@
require 'test_helper'
class ItemTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end