Skip to content

Commit 0e204ac

Browse files
author
Rahoul Baruah
committed
added rspec and cucumber and all that testing gubbins
1 parent b30ec32 commit 0e204ac

File tree

847 files changed

+94322
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

847 files changed

+94322
-0
lines changed

config/environment.rb

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
config.gem "ferret"
2828
config.gem "mislav-will_paginate", :lib => 'will_paginate', :source => 'http://gems.github.com/'
2929
config.gem "recaptcha", :source => 'http://www.loonsoft.com/recaptcha/pkg/'
30+
config.gem 'rahoulb-rujitsu', :lib => 'rujitsu', :source => 'http://gems.github.com/'
3031

3132
# Only load the plugins named here, in the order given. By default, all plugins
3233
# in vendor/plugins are loaded in alphabetical order.
+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Commonly used webrat steps
2+
# http://github.com/brynary/webrat
3+
4+
require 'webrat' if !defined?(Webrat) # Because some people have it installed as a Gem
5+
6+
When /^I press "(.*)"$/ do |button|
7+
clicks_button(button)
8+
end
9+
10+
When /^I follow "(.*)"$/ do |link|
11+
clicks_link(link)
12+
end
13+
14+
When /^I fill in "(.*)" with "(.*)"$/ do |field, value|
15+
fills_in(field, :with => value)
16+
end
17+
18+
When /^I select "(.*)" from "(.*)"$/ do |value, field|
19+
selects(value, :from => field)
20+
end
21+
22+
# Use this step in conjunction with Rail's datetime_select helper. For example:
23+
# When I select "December 25, 2008 10:00" as the date and time
24+
When /^I select "(.*)" as the date and time$/ do |time|
25+
selects_datetime(time)
26+
end
27+
28+
# Use this step when using multiple datetime_select helpers on a page or
29+
# you want to specify which datetime to select. Given the following view:
30+
# <%= f.label :preferred %><br />
31+
# <%= f.datetime_select :preferred %>
32+
# <%= f.label :alternative %><br />
33+
# <%= f.datetime_select :alternative %>
34+
# The following steps would fill out the form:
35+
# When I select "November 23, 2004 11:20" as the "Preferred" data and time
36+
# And I select "November 25, 2004 10:30" as the "Alternative" data and time
37+
When /^I select "(.*)" as the "(.*)" date and time$/ do |datetime, datetime_label|
38+
selects_datetime(datetime, :from => datetime_label)
39+
end
40+
41+
# Use this step in conjuction with Rail's time_select helper. For example:
42+
# When I select "2:20PM" as the time
43+
# Note: Rail's default time helper provides 24-hour time-- not 12 hour time. Webrat
44+
# will convert the 2:20PM to 14:20 and then select it.
45+
When /^I select "(.*)" as the time$/ do |time|
46+
selects_time(time)
47+
end
48+
49+
# Use this step when using multiple time_select helpers on a page or you want to
50+
# specify the name of the time on the form. For example:
51+
# When I select "7:30AM" as the "Gym" time
52+
When /^I select "(.*)" as the "(.*)" time$/ do |time, time_label|
53+
selects_time(time, :from => time_label)
54+
end
55+
56+
# Use this step in conjuction with Rail's date_select helper. For example:
57+
# When I select "February 20, 1981" as the date
58+
When /^I select "(.*)" as the date$/ do |date|
59+
selects_date(date)
60+
end
61+
62+
# Use this step when using multiple date_select helpers on one page or
63+
# you want to specify the name of the date on the form. For example:
64+
# When I select "April 26, 1982" as the "Date of Birth" date
65+
When /^I select "(.*)" as the "(.*)" date$/ do |date, date_label|
66+
selects_date(date, :from => date_label)
67+
end
68+
69+
When /^I check "(.*)"$/ do |field|
70+
checks(field)
71+
end
72+
73+
When /^I uncheck "(.*)"$/ do |field|
74+
unchecks(field)
75+
end
76+
77+
When /^I choose "(.*)"$/ do |field|
78+
chooses(field)
79+
end
80+
81+
When /^I attach the file at "(.*)" to "(.*)" $/ do |path, field|
82+
attaches_file(field, path)
83+
end
84+
85+
Then /^I should see "(.*)"$/ do |text|
86+
response.body.should =~ /#{text}/m
87+
end
88+
89+
Then /^I should not see "(.*)"$/ do |text|
90+
response.body.should_not =~ /#{text}/m
91+
end
92+
93+
Then /^the "(.*)" checkbox should be checked$/ do |label|
94+
field_labeled(label).should be_checked
95+
end

features/support/env.rb

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Sets up the Rails environment for Cucumber
2+
ENV["RAILS_ENV"] = "test"
3+
require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
4+
require 'cucumber/rails/world'
5+
Cucumber::Rails.use_transactional_fixtures
6+
7+
# Comment out the next line if you're not using RSpec's matchers (should / should_not) in your steps.
8+
require 'cucumber/rails/rspec'

lib/tasks/cucumber.rake

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
$:.unshift(RAILS_ROOT + '/vendor/plugins/cucumber/lib')
2+
require 'cucumber/rake/task'
3+
4+
Cucumber::Rake::Task.new(:features) do |t|
5+
t.cucumber_opts = "--format pretty"
6+
end
7+
task :features => 'db:test:prepare'

lib/tasks/rspec.rake

+153
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
raise "To avoid rake task loading problems: run 'rake clobber' in vendor/plugins/rspec" if File.directory?(File.join(File.dirname(__FILE__), *%w[.. .. vendor plugins rspec pkg]))
2+
raise "To avoid rake task loading problems: run 'rake clobber' in vendor/plugins/rspec-rails" if File.directory?(File.join(File.dirname(__FILE__), *%w[.. .. vendor plugins rspec-rails pkg]))
3+
4+
# In rails 1.2, plugins aren't available in the path until they're loaded.
5+
# Check to see if the rspec plugin is installed first and require
6+
# it if it is. If not, use the gem version.
7+
rspec_base = File.expand_path(File.dirname(__FILE__) + '/../../vendor/plugins/rspec/lib')
8+
$LOAD_PATH.unshift(rspec_base) if File.exist?(rspec_base)
9+
10+
begin
11+
require 'spec/rake/spectask'
12+
Rake.application.instance_variable_get('@tasks').delete('default')
13+
14+
spec_prereq = File.exist?(File.join(RAILS_ROOT, 'config', 'database.yml')) ? "db:test:prepare" : :noop
15+
task :noop do
16+
end
17+
18+
task :default => :spec
19+
task :stats => "spec:statsetup"
20+
21+
desc "Run all specs in spec directory (excluding plugin specs)"
22+
Spec::Rake::SpecTask.new(:spec => spec_prereq) do |t|
23+
t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
24+
t.spec_files = FileList['spec/**/*_spec.rb']
25+
end
26+
27+
namespace :spec do
28+
desc "Run all specs in spec directory with RCov (excluding plugin specs)"
29+
Spec::Rake::SpecTask.new(:rcov) do |t|
30+
t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
31+
t.spec_files = FileList['spec/**/*_spec.rb']
32+
t.rcov = true
33+
t.rcov_opts = lambda do
34+
IO.readlines("#{RAILS_ROOT}/spec/rcov.opts").map {|l| l.chomp.split " "}.flatten
35+
end
36+
end
37+
38+
desc "Print Specdoc for all specs (excluding plugin specs)"
39+
Spec::Rake::SpecTask.new(:doc) do |t|
40+
t.spec_opts = ["--format", "specdoc", "--dry-run"]
41+
t.spec_files = FileList['spec/**/*_spec.rb']
42+
end
43+
44+
desc "Print Specdoc for all plugin examples"
45+
Spec::Rake::SpecTask.new(:plugin_doc) do |t|
46+
t.spec_opts = ["--format", "specdoc", "--dry-run"]
47+
t.spec_files = FileList['vendor/plugins/**/spec/**/*_spec.rb'].exclude('vendor/plugins/rspec/*')
48+
end
49+
50+
[:models, :controllers, :views, :helpers, :lib].each do |sub|
51+
desc "Run the code examples in spec/#{sub}"
52+
Spec::Rake::SpecTask.new(sub => spec_prereq) do |t|
53+
t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
54+
t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
55+
end
56+
end
57+
58+
desc "Run the code examples in vendor/plugins (except RSpec's own)"
59+
Spec::Rake::SpecTask.new(:plugins => spec_prereq) do |t|
60+
t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
61+
t.spec_files = FileList['vendor/plugins/**/spec/**/*_spec.rb'].exclude('vendor/plugins/rspec/*').exclude("vendor/plugins/rspec-rails/*")
62+
end
63+
64+
namespace :plugins do
65+
desc "Runs the examples for rspec_on_rails"
66+
Spec::Rake::SpecTask.new(:rspec_on_rails) do |t|
67+
t.spec_opts = ['--options', "\"#{RAILS_ROOT}/spec/spec.opts\""]
68+
t.spec_files = FileList['vendor/plugins/rspec-rails/spec/**/*_spec.rb']
69+
end
70+
end
71+
72+
# Setup specs for stats
73+
task :statsetup do
74+
require 'code_statistics'
75+
::STATS_DIRECTORIES << %w(Model\ specs spec/models) if File.exist?('spec/models')
76+
::STATS_DIRECTORIES << %w(View\ specs spec/views) if File.exist?('spec/views')
77+
::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers) if File.exist?('spec/controllers')
78+
::STATS_DIRECTORIES << %w(Helper\ specs spec/helpers) if File.exist?('spec/helpers')
79+
::STATS_DIRECTORIES << %w(Library\ specs spec/lib) if File.exist?('spec/lib')
80+
::CodeStatistics::TEST_TYPES << "Model specs" if File.exist?('spec/models')
81+
::CodeStatistics::TEST_TYPES << "View specs" if File.exist?('spec/views')
82+
::CodeStatistics::TEST_TYPES << "Controller specs" if File.exist?('spec/controllers')
83+
::CodeStatistics::TEST_TYPES << "Helper specs" if File.exist?('spec/helpers')
84+
::CodeStatistics::TEST_TYPES << "Library specs" if File.exist?('spec/lib')
85+
::STATS_DIRECTORIES.delete_if {|a| a[0] =~ /test/}
86+
end
87+
88+
namespace :db do
89+
namespace :fixtures do
90+
desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y"
91+
task :load => :environment do
92+
require 'active_record/fixtures'
93+
ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
94+
(ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'spec', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
95+
Fixtures.create_fixtures('spec/fixtures', File.basename(fixture_file, '.*'))
96+
end
97+
end
98+
end
99+
end
100+
101+
namespace :server do
102+
daemonized_server_pid = File.expand_path("spec_server.pid", RAILS_ROOT + "/tmp")
103+
104+
desc "start spec_server."
105+
task :start do
106+
if File.exist?(daemonized_server_pid)
107+
$stderr.puts "spec_server is already running."
108+
else
109+
$stderr.puts "Starting up spec server."
110+
system("ruby", "script/spec_server", "--daemon", "--pid", daemonized_server_pid)
111+
end
112+
end
113+
114+
desc "stop spec_server."
115+
task :stop do
116+
unless File.exist?(daemonized_server_pid)
117+
$stderr.puts "No server running."
118+
else
119+
$stderr.puts "Shutting down spec_server."
120+
system("kill", "-s", "TERM", File.read(daemonized_server_pid).strip) &&
121+
File.delete(daemonized_server_pid)
122+
end
123+
end
124+
125+
desc "reload spec_server."
126+
task :restart do
127+
unless File.exist?(daemonized_server_pid)
128+
$stderr.puts "No server running."
129+
else
130+
$stderr.puts "Reloading down spec_server."
131+
system("kill", "-s", "USR2", File.read(daemonized_server_pid).strip)
132+
end
133+
end
134+
end
135+
end
136+
rescue MissingSourceFile
137+
# if rspec-rails is a configured gem, this will output helpful material and exit ...
138+
require File.expand_path(File.dirname(__FILE__) + "/../../config/environment")
139+
140+
# ... otherwise, do this:
141+
raise <<-MSG
142+
143+
You have rspec-rails rake tasks installed in
144+
#{__FILE__},
145+
but rspec-rails is not configured as a gem in
146+
config/environment.rb
147+
148+
Either remove #{__FILE__}
149+
or configure the rspec-rails gem in config/environment.rb.
150+
151+
MSG
152+
end
153+

script/autospec

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env ruby
2+
ENV['RSPEC'] = 'true' # allows autotest to discover rspec
3+
ENV['AUTOTEST'] = 'true' # allows autotest to run w/ color on linux
4+
system((RUBY_PLATFORM =~ /mswin|mingw/ ? 'autotest.bat' : 'autotest'), *ARGV) ||
5+
$stderr.puts("Unable to find autotest. Please install ZenTest or fix your PATH")

script/cucumber

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env ruby
2+
begin
3+
load File.expand_path(File.dirname(__FILE__) + "/../vendor/plugins/cucumber/bin/cucumber")
4+
rescue LoadError
5+
require "rubygems"
6+
load File.join(Gem.bindir, "cucumber")
7+
end

script/spec

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env ruby
2+
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../vendor/plugins/rspec/lib"))
3+
require 'rubygems'
4+
require 'spec'
5+
exit ::Spec::Runner::CommandLine.run(::Spec::Runner::OptionParser.parse(ARGV, STDERR, STDOUT))

0 commit comments

Comments
 (0)