Permalink
Browse files

switch to use rspec for tests

  • Loading branch information...
1 parent cb4a53c commit 4925fd526e714ea74560859b59d9d59c5a291a32 @mjankowski mjankowski committed Sep 3, 2011
Showing with 215 additions and 138 deletions.
  1. +3 −5 .gitignore
  2. +9 −3 Gemfile
  3. +83 −44 Gemfile.lock
  4. +5 −9 Rakefile
  5. +37 −0 spec/controllers/pages_controller_spec.rb
  6. 0 {test → spec}/dummy/Rakefile
  7. 0 {test → spec}/dummy/app/controllers/application_controller.rb
  8. 0 {test → spec}/dummy/app/helpers/application_helper.rb
  9. 0 {test → spec}/dummy/app/views/layouts/application.html.erb
  10. 0 {test → spec}/dummy/app/views/other/wrong.html.erb
  11. 0 {test → spec}/dummy/app/views/pages/dir/nested.html.erb
  12. 0 {test → spec}/dummy/app/views/pages/exists.html.erb
  13. 0 {test → spec}/dummy/app/views/pages/exists_but_references_nonexistent_partial.html.erb
  14. 0 {test → spec}/dummy/config.ru
  15. 0 {test → spec}/dummy/config/application.rb
  16. 0 {test → spec}/dummy/config/boot.rb
  17. +1 −1 {test → spec}/dummy/config/database.yml
  18. 0 {test → spec}/dummy/config/environment.rb
  19. 0 {test → spec}/dummy/config/environments/development.rb
  20. 0 {test → spec}/dummy/config/environments/production.rb
  21. 0 {test → spec}/dummy/config/environments/test.rb
  22. 0 {test → spec}/dummy/config/initializers/backtrace_silencers.rb
  23. 0 {test → spec}/dummy/config/initializers/inflections.rb
  24. 0 {test → spec}/dummy/config/initializers/mime_types.rb
  25. +1 −1 {test → spec}/dummy/config/initializers/secret_token.rb
  26. 0 {test → spec}/dummy/config/initializers/session_store.rb
  27. 0 {test → spec}/dummy/config/locales/en.yml
  28. 0 {test → spec}/dummy/config/routes.rb
  29. 0 {test → spec}/dummy/public/404.html
  30. 0 {test → spec}/dummy/public/422.html
  31. 0 {test → spec}/dummy/public/500.html
  32. 0 {test → spec}/dummy/public/favicon.ico
  33. 0 {test → spec}/dummy/public/javascripts/application.js
  34. 0 {test → spec}/dummy/public/javascripts/controls.js
  35. 0 {test → spec}/dummy/public/javascripts/dragdrop.js
  36. 0 {test → spec}/dummy/public/javascripts/effects.js
  37. 0 {test → spec}/dummy/public/javascripts/prototype.js
  38. +16 −0 {test → spec}/dummy/public/javascripts/rails.js
  39. 0 {test → spec}/dummy/public/stylesheets/.gitkeep
  40. 0 {test → spec}/dummy/script/rails
  41. +7 −0 spec/high_voltage_spec.rb
  42. +9 −0 spec/integration/navigation_spec.rb
  43. +29 −0 spec/routing/routes_spec.rb
  44. +15 −4 test/test_helper.rb → spec/spec_helper.rb
  45. 0 test/dummy/db/.gitkeep
  46. +0 −40 test/pages_controller_test.rb
  47. +0 −31 test/routes_test.rb
View
@@ -1,8 +1,6 @@
-*.swp
-*.swo
.bundle/
log/*.log
pkg/
-test/dummy/db/*.sqlite3
-test/dummy/log/*.log
-test/dummy/tmp/
+spec/dummy/db/*.sqlite3
+spec/dummy/log/*.log
+spec/dummy/tmp/
View
@@ -1,5 +1,11 @@
source "http://rubygems.org"
-gem "rails", "3.0.3"
-gem "sqlite3-ruby", :require => "sqlite3"
-gem "shoulda"
+gem "rails", "3.0.10"
+gem "capybara", ">= 0.4.0"
+gem "sqlite3"
+
+gem "rspec-rails", ">= 2.0.0.beta"
+
+# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
+# gem 'ruby-debug'
+# gem 'ruby-debug19'
View
@@ -2,74 +2,113 @@ GEM
remote: http://rubygems.org/
specs:
abstract (1.0.0)
- actionmailer (3.0.3)
- actionpack (= 3.0.3)
- mail (~> 2.2.9)
- actionpack (3.0.3)
- activemodel (= 3.0.3)
- activesupport (= 3.0.3)
+ actionmailer (3.0.10)
+ actionpack (= 3.0.10)
+ mail (~> 2.2.19)
+ actionpack (3.0.10)
+ activemodel (= 3.0.10)
+ activesupport (= 3.0.10)
builder (~> 2.1.2)
erubis (~> 2.6.6)
- i18n (~> 0.4)
+ i18n (~> 0.5.0)
rack (~> 1.2.1)
- rack-mount (~> 0.6.13)
- rack-test (~> 0.5.6)
+ rack-mount (~> 0.6.14)
+ rack-test (~> 0.5.7)
tzinfo (~> 0.3.23)
- activemodel (3.0.3)
- activesupport (= 3.0.3)
+ activemodel (3.0.10)
+ activesupport (= 3.0.10)
builder (~> 2.1.2)
- i18n (~> 0.4)
- activerecord (3.0.3)
- activemodel (= 3.0.3)
- activesupport (= 3.0.3)
- arel (~> 2.0.2)
+ i18n (~> 0.5.0)
+ activerecord (3.0.10)
+ activemodel (= 3.0.10)
+ activesupport (= 3.0.10)
+ arel (~> 2.0.10)
tzinfo (~> 0.3.23)
- activeresource (3.0.3)
- activemodel (= 3.0.3)
- activesupport (= 3.0.3)
- activesupport (3.0.3)
- arel (2.0.6)
+ activeresource (3.0.10)
+ activemodel (= 3.0.10)
+ activesupport (= 3.0.10)
+ activesupport (3.0.10)
+ arel (2.0.10)
builder (2.1.2)
+ capybara (1.0.0)
+ mime-types (>= 1.16)
+ nokogiri (>= 1.3.3)
+ rack (>= 1.0.0)
+ rack-test (>= 0.5.4)
+ selenium-webdriver (~> 0.2.0)
+ xpath (~> 0.1.4)
+ childprocess (0.2.2)
+ ffi (~> 1.0.6)
+ diff-lcs (1.1.3)
erubis (2.6.6)
abstract (>= 1.0.0)
+ ffi (1.0.9)
i18n (0.5.0)
- mail (2.2.12)
+ json_pure (1.5.4)
+ spruz (~> 0.2.8)
+ mail (2.2.19)
activesupport (>= 2.3.6)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.16)
- polyglot (0.3.1)
- rack (1.2.1)
- rack-mount (0.6.13)
+ nokogiri (1.5.0)
+ polyglot (0.3.2)
+ rack (1.2.3)
+ rack-mount (0.6.14)
rack (>= 1.0.0)
- rack-test (0.5.6)
+ rack-test (0.5.7)
rack (>= 1.0)
- rails (3.0.3)
- actionmailer (= 3.0.3)
- actionpack (= 3.0.3)
- activerecord (= 3.0.3)
- activeresource (= 3.0.3)
- activesupport (= 3.0.3)
+ rails (3.0.10)
+ actionmailer (= 3.0.10)
+ actionpack (= 3.0.10)
+ activerecord (= 3.0.10)
+ activeresource (= 3.0.10)
+ activesupport (= 3.0.10)
bundler (~> 1.0)
- railties (= 3.0.3)
- railties (3.0.3)
- actionpack (= 3.0.3)
- activesupport (= 3.0.3)
+ railties (= 3.0.10)
+ railties (3.0.10)
+ actionpack (= 3.0.10)
+ activesupport (= 3.0.10)
rake (>= 0.8.7)
+ rdoc (~> 3.4)
thor (~> 0.14.4)
- rake (0.8.7)
- shoulda (2.11.3)
- sqlite3-ruby (1.3.2)
+ 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)
+ rubyzip (0.9.4)
+ selenium-webdriver (0.2.2)
+ childprocess (>= 0.1.9)
+ ffi (>= 1.0.7)
+ json_pure
+ rubyzip
+ spruz (0.2.13)
+ sqlite3 (1.3.4)
thor (0.14.6)
- treetop (1.4.9)
+ treetop (1.4.10)
+ polyglot
polyglot (>= 0.3.1)
- tzinfo (0.3.23)
+ tzinfo (0.3.29)
+ xpath (0.1.4)
+ nokogiri (~> 1.3)
PLATFORMS
ruby
DEPENDENCIES
- rails (= 3.0.3)
- shoulda
- sqlite3-ruby
+ capybara (>= 0.4.0)
+ rails (= 3.0.10)
+ rspec-rails (>= 2.0.0.beta)
+ sqlite3
View
@@ -7,18 +7,14 @@ rescue LoadError
end
require 'rake'
-require 'rake/rdoctask'
+require 'rdoc/task'
-require 'rake/testtask'
+require 'rspec/core'
+require 'rspec/core/rake_task'
-Rake::TestTask.new(:test) do |t|
- t.libs << 'lib'
- t.libs << 'test'
- t.pattern = 'test/**/*_test.rb'
- t.verbose = false
-end
+RSpec::Core::RakeTask.new(:spec)
-task :default => :test
+task :default => :spec
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
@@ -0,0 +1,37 @@
+require 'spec_helper'
+
+describe HighVoltage::PagesController do
+
+ render_views
+
+ describe"on GET to /pages/exists" do
+ before { get :show, :id => 'exists' }
+
+ it "should respond with success and render template" do
+ response.should be_success
+ response.should render_template('exists')
+ end
+ end
+
+ describe "on GET to /pages/dir/nested" do
+ before { get :show, :id => 'dir/nested' }
+
+ it "should respond with success and render template" do
+ response.should be_success
+ response.should render_template('pages/dir/nested')
+ end
+ end
+
+ 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)
+ 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)
+ end
+
+end
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -1,5 +1,5 @@
# SQLite version 3.x
-# gem install sqlite3-ruby (not necessary on OS X Leopard)
+# gem install sqlite3
development:
adapter: sqlite3
database: db/development.sqlite3
@@ -4,4 +4,4 @@
# If you change this key, all old signed cookies will become invalid!
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
-Dummy::Application.config.secret_token = '5df838015c4161868ba2fcf1e0f9189835ff44af438ae7cd650d42d1632f18c75a832ec63822a72decfc8832113a2acbcd427e85bf9b7cf8066b5a26e9265d66'
+Dummy::Application.config.secret_token = 'b8d5d5687c012c2ef1a7a6e8006172402c48a3dcccca67c076eaad81c4712ad236ca2717c3706df7b286468c749d223f22acb0d96c27bdf33bbdbb9684ad46e5'
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -172,4 +172,20 @@
input.disabled = false;
});
});
+
+ Ajax.Responders.register({
+ onCreate: function(request) {
+ var csrf_meta_tag = $$('meta[name=csrf-token]')[0];
+
+ if (csrf_meta_tag) {
+ var header = 'X-CSRF-Token',
+ token = csrf_meta_tag.readAttribute('content');
+
+ if (!request.options.requestHeaders) {
+ request.options.requestHeaders = {};
+ }
+ request.options.requestHeaders[header] = token;
+ }
+ }
+ });
})();
File renamed without changes.
@@ -0,0 +1,7 @@
+require 'spec_helper'
+
+describe HighVoltage do
+ it "should be valid" do
+ HighVoltage.should be_a(Module)
+ end
+end
@@ -0,0 +1,9 @@
+require 'spec_helper'
+
+describe "Navigation" do
+ include Capybara::DSL
+
+ it "should be a valid app" do
+ ::Rails.application.should be_a(Dummy::Application)
+ end
+end
@@ -0,0 +1,29 @@
+require 'spec_helper'
+
+describe 'routes' do
+
+ it "should generate normal resource route with id" do
+ page_path(:id => "one").should == "/pages/one"
+ end
+
+ it "should generate normal resource route with string" do
+ page_path("one").should == "/pages/one"
+ end
+
+ it "should generate nested route with string" do
+ page_path("one/two").should == "/pages/one/two"
+ end
+
+ it "should recognize nested route" do
+ 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")
+ 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")
+ end
+
+end
@@ -3,20 +3,31 @@
require File.expand_path("../dummy/config/environment.rb", __FILE__)
require "rails/test_help"
+require "rspec/rails"
ActionMailer::Base.delivery_method = :test
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.default_url_options[:host] = "test.com"
-require "shoulda"
-require "shoulda/rails"
-
Rails.backtrace_cleaner.remove_silencers!
-begin require 'redgreen'; rescue LoadError; end
+# Configure capybara for integration testing
+require "capybara/rails"
+Capybara.default_driver = :rack_test
+Capybara.default_selector = :css
# Run any available migration
ActiveRecord::Migrator.migrate File.expand_path("../dummy/db/migrate/", __FILE__)
# 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
No changes.
Oops, something went wrong.

0 comments on commit 4925fd5

Please sign in to comment.