Commit 5d936b8734fdd2c36a29a5bfdc9ac24872e2647c

spec init, still half of them break

Commit diff

script/spec

 
1#!/usr/bin/env ruby
2$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../vendor/plugins/rspec/lib"))
3require 'spec'
4exit ::Spec::Runner::CommandLine.run(::Spec::Runner::OptionParser.parse(ARGV, STDERR, STDOUT))
toggle raw diff

script/spec_server

 
1#!/usr/bin/env ruby
2$LOAD_PATH.unshift File.dirname(__FILE__) + '/../../rspec/lib' # For svn
3$LOAD_PATH.unshift File.dirname(__FILE__) + '/../vendor/plugins/rspec/lib' # For rspec installed as plugin
4require 'rubygems'
5require 'drb/drb'
6require 'rbconfig'
7require 'spec'
8require 'optparse'
9
10# This is based on Florian Weber's TDDMate
11module Spec
12 module Runner
13 class RailsSpecServer
14 def run(argv, stderr, stdout)
15 $stdout = stdout
16 $stderr = stderr
17
18 base = ActiveRecord::Base
19 def base.clear_reloadable_connections!
20 active_connections.each do |name, conn|
21 if conn.requires_reloading?
22 conn.disconnect!
23 active_connections.delete(name)
24 end
25 end
26 end
27
28 if ActionController.const_defined?(:Dispatcher)
29 dispatcher = ::ActionController::Dispatcher.new($stdout)
30 dispatcher.cleanup_application(true)
31 elsif ::Dispatcher.respond_to?(:reset_application!)
32 ::Dispatcher.reset_application!
33 else
34 raise "Application reloading failed"
35 end
36 ::Dependencies.mechanism = :load
37 require_dependency('application.rb') unless Object.const_defined?(:ApplicationController)
38 load File.dirname(__FILE__) + '/../spec/spec_helper.rb'
39
40 ::Spec::Runner::CommandLine.run(
41 ::Spec::Runner::OptionParser.parse(
42 argv,
43 $stderr,
44 $stdout
45 )
46 )
47 end
48 end
49 end
50end
51puts "Loading Rails environment"
52
53ENV["RAILS_ENV"] = "test"
54require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
55require 'dispatcher'
56
57def restart_test_server
58 puts "restarting"
59 config = ::Config::CONFIG
60 ruby = File::join(config['bindir'], config['ruby_install_name']) + config['EXEEXT']
61 command_line = [ruby, $0, ARGV].flatten.join(' ')
62 exec(command_line)
63end
64
65def daemonize(pid_file = nil)
66 return yield if $DEBUG
67 pid = Process.fork{
68 Process.setsid
69 Dir.chdir(RAILS_ROOT)
70 trap("SIGINT"){ exit! 0 }
71 trap("SIGTERM"){ exit! 0 }
72 trap("SIGHUP"){ restart_test_server }
73 File.open("/dev/null"){|f|
74 STDERR.reopen f
75 STDIN.reopen f
76 STDOUT.reopen f
77 }
78 yield
79 }
80 puts "spec_server launched. (PID: %d)" % pid
81 File.open(pid_file,"w"){|f| f.puts pid } if pid_file
82 exit! 0
83end
84
85options = Hash.new
86opts = OptionParser.new
87opts.on("-d", "--daemon"){|v| options[:daemon] = true }
88opts.on("-p", "--pid PIDFILE"){|v| options[:pid] = v }
89opts.parse!(ARGV)
90
91puts "Ready"
92exec_server = lambda {
93 trap("USR2") { restart_test_server } if Signal.list.has_key?("USR2")
94 DRb.start_service("druby://localhost:8989", Spec::Runner::RailsSpecServer.new)
95 DRb.thread.join
96}
97
98if options[:daemon]
99 daemonize(options[:pid], &exec_server)
100else
101 exec_server.call
102end
toggle raw diff

spec/rcov.opts

 
1--exclude "spec/*,gems/*"
2--rails
toggle raw diff

spec/spec.opts

 
1--colour
2--format
3progress
4--loadby
5mtime
6--reverse
toggle raw diff

spec/spec_helper.rb

 
1# This file is copied to ~/spec when you run 'ruby script/generate rspec'
2# from the project root directory.
3ENV["RAILS_ENV"] = "test"
4require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
5require 'spec'
6require 'spec/rails'
7
8Spec::Runner.configure do |config|
9 # If you're not using ActiveRecord you should remove these
10 # lines, delete config/database.yml and disable :active_record
11 # in your config/boot.rb
12 config.use_transactional_fixtures = true
13 config.use_instantiated_fixtures = false
14 config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
15
16 # == Fixtures
17 #
18 # You can declare fixtures for each example_group like this:
19 # describe "...." do
20 # fixtures :table_a, :table_b
21 #
22 # Alternatively, if you prefer to declare them only once, you can
23 # do so right here. Just uncomment the next line and replace the fixture
24 # names with your fixtures.
25 #
26 # config.global_fixtures = :table_a, :table_b
27 #
28 # If you declare global fixtures, be aware that they will be declared
29 # for all of your examples, even those that don't use them.
30 #
31 # == Mock Framework
32 #
33 # RSpec uses it's own mocking framework by default. If you prefer to
34 # use mocha, flexmock or RR, uncomment the appropriate line:
35 #
36 # config.mock_with :mocha
37 # config.mock_with :flexmock
38 # config.mock_with :rr
39end
toggle raw diff

stories/all.rb

 
1dir = File.dirname(__FILE__)
2Dir[File.expand_path("#{dir}/**/*.rb")].uniq.each do |file|
3 require file
4end
toggle raw diff

stories/helper.rb

 
1ENV["RAILS_ENV"] = "test"
2require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
3require 'spec/rails/story_adapter'
toggle raw diff