From 9ea67909ccafc2f359ebd55f8b942b23cd96c600 Mon Sep 17 00:00:00 2001 From: Aaron Mueller Date: Wed, 23 May 2012 23:55:53 +0200 Subject: [PATCH] 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) --- .rspec | 1 + .watchr | 19 +++++++++ Gemfile | 11 ++++- Gemfile.lock | 19 +++++++++ spec/feed_spec.rb | 1 + spec/item_spec.rb | 9 ++++ .../.gitkeep => spec/models/feed_spec.rb | 0 spec/models/item_spec.rb | 8 ++++ spec/spec_helper.rb | 41 +++++++++++++++++++ test/fixtures/.gitkeep | 0 test/fixtures/feeds.yml | 9 ---- test/fixtures/items.yml | 15 ------- test/functional/.gitkeep | 0 test/functional/feeds_controller_test.rb | 7 ---- test/functional/items_controller_test.rb | 7 ---- test/integration/.gitkeep | 0 test/performance/browsing_test.rb | 12 ------ test/test_helper.rb | 13 ------ test/unit/.gitkeep | 0 test/unit/feed_test.rb | 7 ---- test/unit/helpers/feed_helper_test.rb | 4 -- test/unit/helpers/items_helper_test.rb | 4 -- test/unit/item_test.rb | 7 ---- 23 files changed, 108 insertions(+), 86 deletions(-) create mode 100644 .rspec create mode 100644 .watchr create mode 100644 spec/feed_spec.rb create mode 100644 spec/item_spec.rb rename lib/tasks/.gitkeep => spec/models/feed_spec.rb (100%) create mode 100644 spec/models/item_spec.rb create mode 100644 spec/spec_helper.rb delete mode 100644 test/fixtures/.gitkeep delete mode 100644 test/fixtures/feeds.yml delete mode 100644 test/fixtures/items.yml delete mode 100644 test/functional/.gitkeep delete mode 100644 test/functional/feeds_controller_test.rb delete mode 100644 test/functional/items_controller_test.rb delete mode 100644 test/integration/.gitkeep delete mode 100644 test/performance/browsing_test.rb delete mode 100644 test/test_helper.rb delete mode 100644 test/unit/.gitkeep delete mode 100644 test/unit/feed_test.rb delete mode 100644 test/unit/helpers/feed_helper_test.rb delete mode 100644 test/unit/helpers/items_helper_test.rb delete mode 100644 test/unit/item_test.rb diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..5902dd3 --- /dev/null +++ b/.rspec @@ -0,0 +1 @@ +--colour --drb diff --git a/.watchr b/.watchr new file mode 100644 index 0000000..7dcccf4 --- /dev/null +++ b/.watchr @@ -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 + diff --git a/Gemfile b/Gemfile index 3f8b85e..a554e90 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,7 @@ source 'https://rubygems.org' gem 'rails', '3.2.0' +gem 'jquery-rails' # Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git' @@ -21,7 +22,15 @@ group :assets do gem 'uglifier', '>= 1.0.3' 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 # gem 'bcrypt-ruby', '~> 3.0.0' diff --git a/Gemfile.lock b/Gemfile.lock index af2411a..f3c52d4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -38,6 +38,7 @@ GEM execjs coffee-script-source (1.2.0) curb (0.7.18) + diff-lcs (1.1.3) erubis (2.7.0) execjs (1.3.0) multi_json (~> 1.0) @@ -93,6 +94,19 @@ GEM rake (0.9.2.2) rdoc (3.12) 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-rails (3.2.5) railties (~> 3.2.0) @@ -100,6 +114,7 @@ GEM tilt (~> 1.3) sax-machine (0.0.20) nokogiri (> 0.0.0) + spork (0.9.2) sprockets (2.1.2) hike (~> 1.2) rack (~> 1.0) @@ -114,6 +129,7 @@ GEM uglifier (1.2.4) execjs (>= 0.3.0) multi_json (>= 1.0.2) + watchr (0.7) PLATFORMS ruby @@ -123,6 +139,9 @@ DEPENDENCIES feedzirra jquery-rails rails (= 3.2.0) + rspec-rails (>= 2.7) sass-rails (~> 3.2.3) + spork (~> 0.9.0.rc) sqlite3 uglifier (>= 1.0.3) + watchr diff --git a/spec/feed_spec.rb b/spec/feed_spec.rb new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/spec/feed_spec.rb @@ -0,0 +1 @@ + diff --git a/spec/item_spec.rb b/spec/item_spec.rb new file mode 100644 index 0000000..8976513 --- /dev/null +++ b/spec/item_spec.rb @@ -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 + diff --git a/lib/tasks/.gitkeep b/spec/models/feed_spec.rb similarity index 100% rename from lib/tasks/.gitkeep rename to spec/models/feed_spec.rb diff --git a/spec/models/item_spec.rb b/spec/models/item_spec.rb new file mode 100644 index 0000000..bc960b9 --- /dev/null +++ b/spec/models/item_spec.rb @@ -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 + diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..1e3e3b4 --- /dev/null +++ b/spec/spec_helper.rb @@ -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 diff --git a/test/fixtures/.gitkeep b/test/fixtures/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/test/fixtures/feeds.yml b/test/fixtures/feeds.yml deleted file mode 100644 index 0fe3f4e..0000000 --- a/test/fixtures/feeds.yml +++ /dev/null @@ -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 diff --git a/test/fixtures/items.yml b/test/fixtures/items.yml deleted file mode 100644 index 4ce5338..0000000 --- a/test/fixtures/items.yml +++ /dev/null @@ -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 diff --git a/test/functional/.gitkeep b/test/functional/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/test/functional/feeds_controller_test.rb b/test/functional/feeds_controller_test.rb deleted file mode 100644 index 6d26a84..0000000 --- a/test/functional/feeds_controller_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class FeedsControllerTest < ActionController::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/functional/items_controller_test.rb b/test/functional/items_controller_test.rb deleted file mode 100644 index 5f54afb..0000000 --- a/test/functional/items_controller_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class ItemsControllerTest < ActionController::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/integration/.gitkeep b/test/integration/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/test/performance/browsing_test.rb b/test/performance/browsing_test.rb deleted file mode 100644 index 3fea27b..0000000 --- a/test/performance/browsing_test.rb +++ /dev/null @@ -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 diff --git a/test/test_helper.rb b/test/test_helper.rb deleted file mode 100644 index 8bf1192..0000000 --- a/test/test_helper.rb +++ /dev/null @@ -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 diff --git a/test/unit/.gitkeep b/test/unit/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/test/unit/feed_test.rb b/test/unit/feed_test.rb deleted file mode 100644 index b018d6b..0000000 --- a/test/unit/feed_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class FeedTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end diff --git a/test/unit/helpers/feed_helper_test.rb b/test/unit/helpers/feed_helper_test.rb deleted file mode 100644 index db262f4..0000000 --- a/test/unit/helpers/feed_helper_test.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'test_helper' - -class FeedHelperTest < ActionView::TestCase -end diff --git a/test/unit/helpers/items_helper_test.rb b/test/unit/helpers/items_helper_test.rb deleted file mode 100644 index b2f7c49..0000000 --- a/test/unit/helpers/items_helper_test.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'test_helper' - -class ItemsHelperTest < ActionView::TestCase -end diff --git a/test/unit/item_test.rb b/test/unit/item_test.rb deleted file mode 100644 index f564d81..0000000 --- a/test/unit/item_test.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'test_helper' - -class ItemTest < ActiveSupport::TestCase - # test "the truth" do - # assert true - # end -end