Skip to content

Commit

Permalink
switch to use rspec for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mjankowski committed Sep 3, 2011
1 parent cb4a53c commit 4925fd5
Show file tree
Hide file tree
Showing 47 changed files with 215 additions and 138 deletions.
8 changes: 3 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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/
12 changes: 9 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -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'
127 changes: 83 additions & 44 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 5 additions & 9 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
37 changes: 37 additions & 0 deletions spec/controllers/pages_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -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.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
File renamed without changes.
7 changes: 7 additions & 0 deletions spec/high_voltage_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'spec_helper'

describe HighVoltage do
it "should be valid" do
HighVoltage.should be_a(Module)
end
end
9 changes: 9 additions & 0 deletions spec/integration/navigation_spec.rb
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions spec/routing/routes_spec.rb
Original file line number Diff line number Diff line change
@@ -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
19 changes: 15 additions & 4 deletions test/test_helper.rb → spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Empty file.
Loading

0 comments on commit 4925fd5

Please sign in to comment.