aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xscript/spec4
-rwxr-xr-xscript/spec_server86
-rw-r--r--spec/controllers/admin_public_body_controller_spec.rb9
-rw-r--r--spec/models/user_spec.rb15
-rw-r--r--spec/spec.opts6
-rw-r--r--spec/spec_helper.rb23
6 files changed, 143 insertions, 0 deletions
diff --git a/script/spec b/script/spec
new file mode 100755
index 000000000..d318f1ae3
--- /dev/null
+++ b/script/spec
@@ -0,0 +1,4 @@
+#!/usr/bin/env ruby
+$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../vendor/plugins/rspec/lib"))
+require 'spec'
+::Spec::Runner::CommandLine.run(ARGV, STDERR, STDOUT, true, true)
diff --git a/script/spec_server b/script/spec_server
new file mode 100755
index 000000000..cac91e2b8
--- /dev/null
+++ b/script/spec_server
@@ -0,0 +1,86 @@
+#!/usr/bin/env ruby
+$LOAD_PATH.unshift File.dirname(__FILE__) + '/../../rspec/lib' # For svn
+$LOAD_PATH.unshift File.dirname(__FILE__) + '/../vendor/plugins/rspec/lib' # For rspec installed as plugin
+require 'rubygems'
+require 'drb/drb'
+require 'rbconfig'
+require 'spec'
+require 'optparse'
+specmate = ENV['HOME'] + "/Library/Application\ Support/TextMate/Bundles/RSpec.tmbundle/Support/lib"
+if File.directory?(specmate)
+ $LOAD_PATH.unshift(specmate)
+ require 'text_mate_formatter'
+end
+
+# This is based on Florian Weber's TDDMate
+
+module Spec
+ module Runner
+ class RailsSpecServer
+ def run(args, stderr, stdout)
+ $stdout = stdout
+ $stderr = stderr
+
+ ::Dispatcher.reset_application!
+ ::Dependencies.mechanism = :load
+ require_dependency('application.rb') unless Object.const_defined?(:ApplicationController)
+ load File.dirname(__FILE__) + '/../spec/spec_helper.rb'
+
+ ::Spec::Runner::CommandLine.run(args, stderr, stdout, false, true)
+ end
+ end
+ end
+end
+puts "Loading Rails environment"
+
+ENV["RAILS_ENV"] = "test"
+require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
+require 'dispatcher'
+
+def restart_test_server
+ puts "restarting"
+ config = ::Config::CONFIG
+ ruby = File::join(config['bindir'], config['ruby_install_name']) + config['EXEEXT']
+ command_line = [ruby, $0, ARGV].flatten.join(' ')
+ exec(command_line)
+end
+
+def daemonize(pid_file = nil)
+ return yield if $DEBUG
+ pid = Process.fork{
+ Process.setsid
+ Dir.chdir(RAILS_ROOT)
+ trap("SIGINT"){ exit! 0 }
+ trap("SIGTERM"){ exit! 0 }
+ trap("SIGHUP"){ restart_test_server }
+ File.open("/dev/null"){|f|
+ STDERR.reopen f
+ STDIN.reopen f
+ STDOUT.reopen f
+ }
+ yield
+ }
+ puts "spec_server launched. (PID: %d)" % pid
+ File.open(pid_file,"w"){|f| f.puts pid } if pid_file
+ exit! 0
+end
+
+options = Hash.new
+opts = OptionParser.new
+opts.on("-d", "--daemon"){|v| options[:daemon] = true }
+opts.on("-p", "--pid PIDFILE"){|v| options[:pid] = v }
+opts.parse!(ARGV)
+
+puts "Ready"
+exec_server = lambda {
+ trap("USR2") { restart_test_server } if Signal.list.has_key?("USR2")
+ DRb.start_service("druby://localhost:8989", Spec::Runner::RailsSpecServer.new)
+ DRb.thread.join
+}
+
+if options[:daemon]
+ daemonize(options[:pid], &exec_server)
+else
+ exec_server.call
+end
+
diff --git a/spec/controllers/admin_public_body_controller_spec.rb b/spec/controllers/admin_public_body_controller_spec.rb
new file mode 100644
index 000000000..87f7e1185
--- /dev/null
+++ b/spec/controllers/admin_public_body_controller_spec.rb
@@ -0,0 +1,9 @@
+require File.dirname(__FILE__) + '/../spec_helper'
+
+describe AdminPublicBodyController, "#route_for" do
+
+ it "should map { :controller => 'admin_public_body', :action => 'list' } to /admin/body/list" do
+ route_for(:controller => "admin_public_body", :action => "list").should == "/admin/body/list"
+ end
+
+end
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
new file mode 100644
index 000000000..879006b4b
--- /dev/null
+++ b/spec/models/user_spec.rb
@@ -0,0 +1,15 @@
+require File.dirname(__FILE__) + '/../spec_helper'
+
+describe User, " when authenticating" do
+
+ before do
+ @user = User.new
+ end
+
+ it "should create a hashed password when the password is set" do
+ @user.hashed_password.should be_nil
+ @user.password = "a test password"
+ @user.hashed_password.should_not be_nil
+ end
+
+end \ No newline at end of file
diff --git a/spec/spec.opts b/spec/spec.opts
new file mode 100644
index 000000000..d8c8db5d4
--- /dev/null
+++ b/spec/spec.opts
@@ -0,0 +1,6 @@
+--colour
+--format
+progress
+--loadby
+mtime
+--reverse
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
new file mode 100644
index 000000000..e5d4f2259
--- /dev/null
+++ b/spec/spec_helper.rb
@@ -0,0 +1,23 @@
+# 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(File.dirname(__FILE__) + "/../config/environment")
+require 'spec/rails'
+
+Spec::Runner.configure do |config|
+ config.use_transactional_fixtures = true
+ config.use_instantiated_fixtures = false
+ config.fixture_path = RAILS_ROOT + '/spec/fixtures'
+
+ # You can declare fixtures for each behaviour like this:
+ # describe "...." do
+ # fixtures :table_a, :table_b
+ #
+ # Alternatively, if you prefer to declare them only once, you can
+ # do so here, like so ...
+ #
+ # config.global_fixtures = :table_a, :table_b
+ #
+ # If you declare global fixtures, be aware that they will be declared
+ # for all of your examples, even those that don't use them.
+end