Permalink
Browse files

use rspec for tests

  • Loading branch information...
1 parent 89e08b1 commit 447808d5e963272868051055763436db977e5454 @mjankowski mjankowski committed Sep 4, 2011
View
1 Gemfile
@@ -2,3 +2,4 @@ source "http://rubygems.org"
gemspec
gem "appraisal"
+gem "rspec-rails"
View
27 Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- paul_revere (0.1.5)
+ paul_revere (0.1.6)
rails (~> 3.0)
GEM
@@ -41,9 +41,8 @@ GEM
rake
arel (2.2.1)
bcrypt-ruby (3.0.0)
- bourne (1.0)
- mocha (= 0.9.8)
builder (3.0.0)
+ diff-lcs (1.1.3)
erubis (2.7.0)
hike (1.2.1)
i18n (0.6.0)
@@ -52,8 +51,7 @@ GEM
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.16)
- mocha (0.9.8)
- rake
+ mocha (0.9.12)
multi_json (1.0.3)
polyglot (0.3.2)
rack (1.3.2)
@@ -82,7 +80,19 @@ GEM
thor (~> 0.14.6)
rake (0.9.2)
rdoc (3.9.4)
- shoulda (2.11.3)
+ rspec (2.6.0)
+ rspec-core (~> 2.6.0)
+ rspec-expectations (~> 2.6.0)
+ rspec-mocks (~> 2.6.0)
+ rspec-core (2.6.4)
+ rspec-expectations (2.6.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.6.0)
+ rspec-rails (2.6.1)
+ actionpack (~> 3.0)
+ activesupport (~> 3.0)
+ railties (~> 3.0)
+ rspec (~> 2.6.0)
sprockets (2.0.0)
hike (~> 1.2)
rack (~> 1.0)
@@ -100,7 +110,8 @@ PLATFORMS
DEPENDENCIES
appraisal
- bourne
+ mocha
paul_revere!
- shoulda
+ rspec
+ rspec-rails
sqlite3
View
56 Rakefile
@@ -1,61 +1,31 @@
+# encoding: UTF-8
+require 'rubygems'
+begin
+ require 'bundler/setup'
+rescue LoadError
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
+end
+
require 'rake'
-require 'rake/testtask'
require 'rdoc/task'
-require "rubygems/package_task"
require 'appraisal'
+require 'rspec/core'
+require 'rspec/core/rake_task'
+RSpec::Core::RakeTask.new(:spec)
+
desc "Default: run the unit tests."
task :default => [:all]
desc 'Test the plugin under all supported Rails versions.'
task :all => ["appraisal:install"] do |t|
- exec('rake appraisal test')
-end
-
-desc 'Default: run unit tests.'
-task :default => :test
-
-desc 'Test the paul revere plugin.'
-Rake::TestTask.new(:test) do |t|
- t.libs << 'lib'
- t.libs << 'test'
- t.pattern = 'test/**/*_test.rb'
- t.verbose = true
+ exec('rake appraisal spec')
end
desc 'Generate documentation for the paul revere plugin.'
RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'PaulRevere'
rdoc.options << '--line-numbers' << '--inline-source'
- rdoc.rdoc_files.include('README')
rdoc.rdoc_files.include('lib/**/*.rb')
end
-
-spec = Gem::Specification.new do |s|
- s.name = "paul_revere"
- s.version = "0.1.5"
- s.summary = "Simple announcement plugin to include 'one off' style announcements in Rails web apps."
- s.author = "Thoughtbot"
- s.email = "support@thoughtbot.com"
- s.homepage = "https://github.com/thoughtbot/paul_revere"
- s.has_rdoc = true
- s.extra_rdoc_files = %w(README.textile)
- s.rdoc_options = %w(--main README.textile)
- s.files = %w(init.rb MIT-LICENSE Rakefile README.textile) +
- Dir.glob("{test,lib/**/*,app/**/*}")
- s.require_paths = ["lib"]
-
- s.add_dependency("rails", "~> 3.0.0")
- s.add_development_dependency("bourne")
- s.add_development_dependency("shoulda")
- s.add_development_dependency("redgreen")
-end
-
-desc "Build the gemspec file #{spec.name}.gemspec"
-task :gemspec do
- file = File.dirname(__FILE__) + "/#{spec.name}.gemspec"
- File.open(file, "w") {|f| f << spec.to_ruby }
-end
-
-task :package => :gemspec
View
1 gemfiles/3.0.10.gemfile
@@ -3,6 +3,7 @@
source "http://rubygems.org"
gem "appraisal"
+gem "rspec-rails"
gem "rails", "3.0.10"
gemspec :path=>"../"
View
27 gemfiles/3.0.10.gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: /Users/mjankowski/Development/paul_revere
specs:
- paul_revere (0.1.5)
+ paul_revere (0.1.6)
rails (~> 3.0)
GEM
@@ -38,9 +38,8 @@ GEM
bundler
rake
arel (2.0.10)
- bourne (1.0)
- mocha (= 0.9.8)
builder (2.1.2)
+ diff-lcs (1.1.3)
erubis (2.6.6)
abstract (>= 1.0.0)
i18n (0.5.0)
@@ -50,8 +49,7 @@ GEM
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.16)
- mocha (0.9.8)
- rake
+ mocha (0.9.12)
polyglot (0.3.2)
rack (1.2.3)
rack-mount (0.6.14)
@@ -74,7 +72,19 @@ GEM
thor (~> 0.14.4)
rake (0.9.2)
rdoc (3.9.4)
- shoulda (2.11.3)
+ rspec (2.6.0)
+ rspec-core (~> 2.6.0)
+ rspec-expectations (~> 2.6.0)
+ rspec-mocks (~> 2.6.0)
+ rspec-core (2.6.4)
+ rspec-expectations (2.6.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.6.0)
+ rspec-rails (2.6.1)
+ actionpack (~> 3.0)
+ activesupport (~> 3.0)
+ railties (~> 3.0)
+ rspec (~> 2.6.0)
sqlite3 (1.3.4)
thor (0.14.6)
treetop (1.4.10)
@@ -87,8 +97,9 @@ PLATFORMS
DEPENDENCIES
appraisal
- bourne
+ mocha
paul_revere!
rails (= 3.0.10)
- shoulda
+ rspec
+ rspec-rails
sqlite3
View
1 gemfiles/3.1.0.gemfile
@@ -3,6 +3,7 @@
source "http://rubygems.org"
gem "appraisal"
+gem "rspec-rails"
gem "rails", "3.1.0"
gem "sass-rails"
gem "coffee-script"
View
27 gemfiles/3.1.0.gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: /Users/mjankowski/Development/paul_revere
specs:
- paul_revere (0.1.5)
+ paul_revere (0.1.6)
rails (~> 3.0)
GEM
@@ -41,13 +41,12 @@ GEM
rake
arel (2.2.1)
bcrypt-ruby (3.0.0)
- bourne (1.0)
- mocha (= 0.9.8)
builder (3.0.0)
coffee-script (2.2.0)
coffee-script-source
execjs
coffee-script-source (1.1.2)
+ diff-lcs (1.1.3)
erubis (2.7.0)
execjs (1.2.4)
multi_json (~> 1.0)
@@ -61,8 +60,7 @@ GEM
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.16)
- mocha (0.9.8)
- rake
+ mocha (0.9.12)
multi_json (1.0.3)
polyglot (0.3.2)
rack (1.3.2)
@@ -91,12 +89,24 @@ GEM
thor (~> 0.14.6)
rake (0.9.2)
rdoc (3.9.4)
+ rspec (2.6.0)
+ rspec-core (~> 2.6.0)
+ rspec-expectations (~> 2.6.0)
+ rspec-mocks (~> 2.6.0)
+ rspec-core (2.6.4)
+ rspec-expectations (2.6.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.6.0)
+ rspec-rails (2.6.1)
+ actionpack (~> 3.0)
+ activesupport (~> 3.0)
+ railties (~> 3.0)
+ rspec (~> 2.6.0)
sass (3.1.7)
sass-rails (3.1.0)
actionpack (~> 3.1.0)
railties (~> 3.1.0)
sass (>= 3.1.4)
- shoulda (2.11.3)
sprockets (2.0.0)
hike (~> 1.2)
rack (~> 1.0)
@@ -117,12 +127,13 @@ PLATFORMS
DEPENDENCIES
appraisal
- bourne
coffee-script
jquery-rails
+ mocha
paul_revere!
rails (= 3.1.0)
+ rspec
+ rspec-rails
sass-rails
- shoulda
sqlite3
uglifier
View
50 paul_revere.gemspec
@@ -1,39 +1,15 @@
-# -*- encoding: utf-8 -*-
-
Gem::Specification.new do |s|
- s.name = %q{paul_revere}
- s.version = "0.1.5"
-
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
- s.authors = ["Thoughtbot"]
- s.date = %q{2010-10-16}
- s.email = %q{support@thoughtbot.com}
- s.extra_rdoc_files = ["README.textile"]
- s.files = ["init.rb", "MIT-LICENSE", "Rakefile", "README.textile", "test", "lib/generators", "lib/generators/paul_revere", "lib/generators/paul_revere/paul_revere_generator.rb", "lib/generators/paul_revere/templates", "lib/generators/paul_revere/templates/announcements.js", "lib/generators/paul_revere/templates/migration.rb", "lib/generators/paul_revere/USAGE", "lib/paul_revere.rb", "app/helpers", "app/helpers/announcements_helper.rb", "app/models", "app/models/announcement.rb", "app/views", "app/views/announcements", "app/views/announcements/_announcement.html.erb", "app/views/announcements/_announcement_for_all.html.erb", "app/views/announcements/_email_announcement.erb"]
- s.homepage = %q{http://thoughtbot.com/community}
- s.rdoc_options = ["--main", "README.textile"]
- s.require_paths = ["lib"]
- s.rubygems_version = %q{1.3.7}
- s.summary = %q{Simple announcement plugin to include 'one off' style announcements in Rails web apps.}
-
- if s.respond_to? :specification_version then
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
- s.specification_version = 3
-
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
- s.add_runtime_dependency(%q<rails>, ["~> 3.0"])
- s.add_development_dependency(%q<bourne>, [">= 0"])
- s.add_development_dependency(%q<shoulda>, [">= 0"])
- s.add_development_dependency(%q<sqlite3>, [">= 0"])
- else
- s.add_dependency(%q<rails>, ["~> 3.0"])
- s.add_dependency(%q<bourne>, [">= 0"])
- s.add_dependency(%q<shoulda>, [">= 0"])
- s.add_dependency(%q<sqlite3>, [">= 0"])
- end
- else
- s.add_dependency(%q<rails>, ["~> 3.0"])
- s.add_dependency(%q<bourne>, [">= 0"])
- s.add_dependency(%q<sqlite3>, [">= 0"])
- end
+ s.name = "paul_revere"
+ s.version = "0.1.6"
+ s.date = %q{2011-09-04}
+ s.email = "support@thoughtbot.com"
+ s.homepage = "https://github.com/thoughtbot/paul_revere"
+ s.summary = "Simple announcement plugin to include 'one off' style announcements in Rails web apps."
+ s.description = "Paul Revere provides a model and helper methods to do one-off style announcements."
+ s.files = Dir["{app,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "Gemfile", "README.md", "init.rb"]
+ s.authors = ['Nick Quaranto', 'Matt Jankowski', 'Joe Ferris', 'Christopher Meiklejohn', 'Tammer Saleh', 'Jason Morrison', 'Gabe Berke-Williams']
+ s.add_dependency("rails", "~> 3.0")
+ s.add_development_dependency("rspec")
+ s.add_development_dependency("sqlite3")
+ s.add_development_dependency("mocha")
end
View
16 spec/fake_app.rb
@@ -0,0 +1,16 @@
+# Create a rails app
+module PaulRevere
+ class Application < Rails::Application
+ end
+end
+
+# Run migrations
+project_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
+require File.join project_root, 'lib', 'generators', 'paul_revere', 'templates', 'migration'
+
+ActiveRecord::Base.establish_connection(
+ :adapter => "sqlite3",
+ :database => ":memory:"
+)
+
+CreateAnnouncements.suppress_messages { CreateAnnouncements.up }
View
42 spec/helpers/announcements_helper_spec.rb
@@ -0,0 +1,42 @@
+require 'spec_helper'
+
+require File.join(File.dirname(__FILE__), '..', '..', 'app', 'helpers', 'announcements_helper')
+require File.join(File.dirname(__FILE__), '..', '..', 'app', 'models', 'announcement')
+
+describe AnnouncementsHelper do
+
+ it "should return the current announcement when sent current_announcement and cache doesn't exist" do
+ assign :current_announcement, nil
+ Announcement.stubs(:current).returns(:foo)
+ helper.current_announcement.should == :foo
+ end
+
+ it "should return a cached announcement when sent current_announcement and cache exists" do
+ assign :current_announcement, :foo
+ Announcement.expects(:current).never
+ helper.current_announcement.should == :foo
+ end
+
+ describe "when there is an announcement" do
+ before do
+ @announcement = Announcement.create!(:body => 'a body')
+ assign :announcement, @announcement
+ end
+
+ describe "and the user has hidden an announcement" do
+ before { helper.stubs(:cookies).returns("announcement_#{@announcement.created_at}" => "hidden") }
+
+ it "should return true when sent announcement_hidden? with announcement" do
+ helper.announcement_hidden?(@announcement).should be_true
+ end
+ end
+
+ describe "and the user has not hidden an announcement" do
+ before { helper.stubs(:cookies).returns("announcement_#{@announcement.created_at}" => "not hidden") }
+
+ it "should return false when sent announcement_hidden? with announcement" do
+ helper.announcement_hidden?(@announcement).should be_false
+ end
+ end
+ end
+end
View
22 spec/models/announcement_spec.rb
@@ -0,0 +1,22 @@
+require 'spec_helper'
+
+require File.join(File.dirname(__FILE__), '..', '..', 'app', 'models', 'announcement')
+
+describe Announcement do
+ it "should return the latest announcement when there are several" do
+ old = Announcement.create!(:body => 'no fun', :created_at => 2.days.ago)
+ latest = Announcement.create!(:body => 'fun', :created_at => 1.day.ago)
+ older = Announcement.create!(:body => 'less fun', :created_at => 3.days.ago)
+
+ Announcement.current.should == latest
+ end
+
+ it "should return an existent announcement where there is no announcement" do
+ Announcement.create!(:body => 'body')
+ Announcement.current.exists?.should == true
+ end
+
+ it "should return a non-existent announcement where there is no announcement" do
+ Announcement.current.exists?.should be_false
+ end
+end
View
7 spec/paul_revere_spec.rb
@@ -0,0 +1,7 @@
+require 'spec_helper'
+
+describe PaulRevere do
+ it "should be valid" do
+ PaulRevere.should be_a(Module)
+ end
+end
View
26 spec/spec_helper.rb
@@ -0,0 +1,26 @@
+# Configure Rails Envinronment
+ENV["RAILS_ENV"] = "test"
+
+require "rails/all"
+require "rspec/rails"
+
+# Pull in the fake rails app
+require 'fake_app'
+
+# 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 :mocha
+
+ # Remove announcements before each example
+ config.before(:each) do
+ Announcement.delete_all
+ end
+end
View
21 test/announcement_test.rb
@@ -1,21 +0,0 @@
-require 'test_helper'
-require File.join(File.dirname(__FILE__), '..', 'app', 'models', 'announcement')
-
-class AnnouncementTest < ActiveSupport::TestCase
- should "return the latest announcement when there are several" do
- old = Announcement.create!(:body => 'no fun', :created_at => 2.days.ago)
- latest = Announcement.create!(:body => 'fun', :created_at => 1.day.ago)
- older = Announcement.create!(:body => 'less fun', :created_at => 3.days.ago)
-
- assert_equal latest, Announcement.current
- end
-
- should "return an existent announcement where there is no announcement" do
- Announcement.create!(:body => 'body')
- assert Announcement.current.exists?
- end
-
- should "return a non-existent announcement where there is no announcement" do
- assert ! Announcement.current.exists?
- end
-end
View
41 test/announcements_helper_test.rb
@@ -1,41 +0,0 @@
-require 'test_helper'
-require File.join(File.dirname(__FILE__), '..', 'app', 'helpers', 'announcements_helper')
-require File.join(File.dirname(__FILE__), '..', 'app', 'models', 'announcement')
-
-class AnnouncementsHelperTest < ActionView::TestCase
- include AnnouncementsHelper
-
- should "return the current announcement when sent current_announcement and cache doesn't exist" do
- @current_announcement = nil
- Announcement.stubs(:current).returns(:foo)
- assert_equal :foo, current_announcement
- end
-
- should "return a cached announcement when sent current_announcement and cache exists" do
- @current_announcement = :foo
- Announcement.expects(:current).never
- assert_equal :foo, current_announcement
- end
-
- context "when there is an announcement" do
- setup do
- @announcement = Announcement.create!(:body => 'a body')
- end
-
- context "and the user has hidden an announcement" do
- setup { self.stubs(:cookies).returns("announcement_#{@announcement.created_at}" => "hidden") }
-
- should "return true when sent announcement_hidden? with announcement" do
- assert send(:announcement_hidden?, @announcement)
- end
- end
-
- context "and the user has not hidden an announcement" do
- setup { self.stubs(:cookies).returns("announcement_#{@announcement.created_at}" => "not hidden") }
-
- should "return false when sent announcement_hidden? with announcement" do
- assert !send(:announcement_hidden?, @announcement)
- end
- end
- end
-end
View
28 test/test_helper.rb
@@ -1,28 +0,0 @@
-ENV['RAILS_ENV'] = 'test'
-
-require 'rubygems'
-require 'rails/all'
-require 'shoulda'
-require 'shoulda/rails'
-require 'bourne'
-
-begin require 'redgreen'; rescue LoadError; end
-
-module PaulRevere
- class Application < Rails::Application
- end
-end
-
-class ActiveSupport::TestCase
- setup do
- Announcement.delete_all
- end
-end
-
-PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
-require File.join(PROJECT_ROOT, 'lib', 'generators', 'paul_revere', 'templates', 'migration')
-ActiveRecord::Base.establish_connection(
- :adapter => "sqlite3",
- :database => ":memory:"
-)
-CreateAnnouncements.suppress_messages { CreateAnnouncements.up }

0 comments on commit 447808d

Please sign in to comment.