Permalink
Browse files

The basic structure for rspec

  • Loading branch information...
gnomet committed Jul 5, 2010
1 parent 1fbf1b5 commit fdf746e07f67074c97224e611c99cb6feecf63e6
Showing with 108 additions and 1 deletion.
  1. +1 −0 .rspec
  2. +3 −1 Gemfile
  3. +2 −0 autotest/discover.rb
  4. +6 −0 config/initializers/rspec_generator.rb
  5. +69 −0 lib/tasks/rspec.rake
  6. +27 −0 spec/spec_helper.rb
View
1 .rspec
@@ -0,0 +1 @@
--colour
View
@@ -28,5 +28,7 @@ gem 'sqlite3-ruby', :require => 'sqlite3'
# gem 'webrat'
# end
gem 'mysql', '2.8.1'
gem 'haml'
gem 'haml'
gem "rspec-rails", ">= 2.0.0.beta.13"
View
@@ -0,0 +1,2 @@
Autotest.add_discovery { "rails" }
Autotest.add_discovery { "rspec2" }
@@ -0,0 +1,6 @@
Kassi::Application.configure do
config.generators do |g|
g.integration_tool :rspec
g.test_framework :rspec
end
end if defined? Kassi::Application
View
@@ -0,0 +1,69 @@
begin
require 'rspec/core'
require 'rspec/core/rake_task'
rescue MissingSourceFile
module RSpec
module Core
class RakeTask
def initialize(name)
task name do
# if rspec-rails is a configured gem, this will output helpful material and exit ...
require File.expand_path(File.dirname(__FILE__) + "/../../config/environment")
# ... otherwise, do this:
raise <<-MSG
#{"*" * 80}
* You are trying to run an rspec rake task defined in
* #{__FILE__},
* but rspec can not be found in vendor/gems, vendor/plugins or system gems.
#{"*" * 80}
MSG
end
end
end
end
end
end
Rake.application.instance_variable_get('@tasks').delete('default')
spec_prereq = Rails.root.join('config', 'database.yml').exist? ? "db:test:prepare" : :noop
task :noop do
end
task :default => :spec
task :stats => "spec:statsetup"
desc "Run all specs in spec directory (excluding plugin specs)"
RSpec::Core::RakeTask.new(:spec => spec_prereq)
namespace :spec do
[:requests, :models, :controllers, :views, :helpers, :mailers, :lib, :routing].each do |sub|
desc "Run the code examples in spec/#{sub}"
RSpec::Core::RakeTask.new(sub => spec_prereq) do |t|
t.pattern = "./spec/#{sub}/**/*_spec.rb"
end
end
task :statsetup do
require 'rails/code_statistics'
::STATS_DIRECTORIES << %w(Model\ specs spec/models) if File.exist?('spec/models')
::STATS_DIRECTORIES << %w(View\ specs spec/views) if File.exist?('spec/views')
::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers) if File.exist?('spec/controllers')
::STATS_DIRECTORIES << %w(Helper\ specs spec/helpers) if File.exist?('spec/helpers')
::STATS_DIRECTORIES << %w(Library\ specs spec/lib) if File.exist?('spec/lib')
::STATS_DIRECTORIES << %w(Mailer\ specs spec/mailers) if File.exist?('spec/mailers')
::STATS_DIRECTORIES << %w(Routing\ specs spec/routing) if File.exist?('spec/routing')
::STATS_DIRECTORIES << %w(Request\ specs spec/requests) if File.exist?('spec/requests')
::CodeStatistics::TEST_TYPES << "Model specs" if File.exist?('spec/models')
::CodeStatistics::TEST_TYPES << "View specs" if File.exist?('spec/views')
::CodeStatistics::TEST_TYPES << "Controller specs" if File.exist?('spec/controllers')
::CodeStatistics::TEST_TYPES << "Helper specs" if File.exist?('spec/helpers')
::CodeStatistics::TEST_TYPES << "Library specs" if File.exist?('spec/lib')
::CodeStatistics::TEST_TYPES << "Mailer specs" if File.exist?('spec/mailer')
::CodeStatistics::TEST_TYPES << "Routing specs" if File.exist?('spec/routing')
::CodeStatistics::TEST_TYPES << "Request specs" if File.exist?('spec/requests')
end
end
View
@@ -0,0 +1,27 @@
# This file is copied to ~/spec when you run 'ruby script/generate rspec'
# from the project root directory.
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
Dir["#{File.dirname(__FILE__)}/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
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, comment the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
end

0 comments on commit fdf746e

Please sign in to comment.