From: Mohammed Morsi <mmorsi(a)redhat.com>
(edited by Jason Guiditta <jguiditt(a)redhat.com>)
(edited by Scott Seago <sseago(a)redhat.com>)
---
src/.rspec | 2 +
src/Rakefile | 2 +-
src/autotest/discover.rb | 2 +
src/features/support/env.rb | 6 +-
src/features/support/paths.rb | 2 +-
src/lib/tasks/cucumber.rake | 29 +---
src/lib/tasks/demo_data.rake | 2 +-
src/lib/tasks/rspec.rake | 157 --------------------
src/spec/controllers/pools_controller_spec.rb | 3 +-
.../controllers/user_sessions_controller_spec.rb | 3 +-
src/spec/controllers/users_controller_spec.rb | 1 +
src/spec/models/hardware_profile_spec.rb | 2 +-
src/spec/models/provider_spec.rb | 6 +-
src/spec/models/user_spec.rb | 8 +-
.../services/data_service_active_record_spec.rb | 6 +-
src/spec/services/registration_service_spec.rb | 3 +-
src/spec/spec.opts | 4 -
src/spec/spec_helper.rb | 48 +-----
18 files changed, 42 insertions(+), 244 deletions(-)
create mode 100644 src/.rspec
create mode 100644 src/autotest/discover.rb
delete mode 100644 src/lib/tasks/rspec.rake
delete mode 100644 src/spec/spec.opts
diff --git a/src/.rspec b/src/.rspec
new file mode 100644
index 0000000..89da67b
--- /dev/null
+++ b/src/.rspec
@@ -0,0 +1,2 @@
+--colour
+--format progress
diff --git a/src/Rakefile b/src/Rakefile
index d654057..408a087 100644
--- a/src/Rakefile
+++ b/src/Rakefile
@@ -4,6 +4,6 @@
require File.expand_path('../config/application', __FILE__)
require 'rake'
require 'rake/testtask'
-require 'rake/rdoctask'
+require 'rdoc/task'
Conductor::Application.load_tasks
diff --git a/src/autotest/discover.rb b/src/autotest/discover.rb
new file mode 100644
index 0000000..f421dc5
--- /dev/null
+++ b/src/autotest/discover.rb
@@ -0,0 +1,2 @@
+Autotest.add_discovery { "rails" }
+Autotest.add_discovery { "rspec2" }
diff --git a/src/features/support/env.rb b/src/features/support/env.rb
index 33f9ed2..d06255f 100644
--- a/src/features/support/env.rb
+++ b/src/features/support/env.rb
@@ -4,11 +4,10 @@
# instead of editing this one. Cucumber will automatically load all features/**/*.rb
# files.
-ENV["RAILS_ENV"] ||= "cucumber"
+ENV["RAILS_ENV"] ||= "test"
require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
require 'cucumber/formatter/unicode' # Remove this line if you don't want
Cucumber Unicode support
-require 'cucumber/rails/rspec'
require 'cucumber/rails/world'
require 'cucumber/rails/active_record'
require 'cucumber/web/tableish'
@@ -20,11 +19,10 @@ require 'webrat'
require 'webrat/core/matchers'
Webrat.configure do |config|
- config.mode = :rails
+ config.mode = :rack
config.open_error_files = false # Set to true if you want error pages to pop up in the
browser
end
-
# If you set this to false, any error raised from within your app will bubble
# up to your step definition and out to cucumber unless you catch it somewhere
# on the way. You can make Rails rescue errors and render error pages on a
diff --git a/src/features/support/paths.rb b/src/features/support/paths.rb
index 35f0cfc..1461077 100644
--- a/src/features/support/paths.rb
+++ b/src/features/support/paths.rb
@@ -30,7 +30,7 @@ module NavigationHelpers
account_path
when /the login error page/
- user_session_path
+ url_for :controller => 'user_sessions', :action => 'new',
:only_path => true
when /the providers page/
url_for :controller => 'providers', :action => 'index',
:only_path => true
diff --git a/src/lib/tasks/cucumber.rake b/src/lib/tasks/cucumber.rake
index 453f43c..64cca31 100644
--- a/src/lib/tasks/cucumber.rake
+++ b/src/lib/tasks/cucumber.rake
@@ -43,28 +43,11 @@ begin
task :features => :cucumber do
STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber
***"
end
-
- namespace :hudson do
- def report_path
- "hudson/reports/features/"
- end
-
- Cucumber::Rake::Task.new({'cucumber' => [:report_setup]}) do |t|
- t.cucumber_opts = %{--profile default --format junit --out #{report_path}}
- end
-
- task :report_setup do
- rm_rf report_path
- mkdir_p report_path
- end
-
- end
-
- rescue LoadError
- desc 'cucumber rake task not available (cucumber not installed)'
- task :cucumber do
- abort 'Cucumber rake task is not available. Be sure to install cucumber as a
gem or plugin'
- end
+rescue LoadError
+ desc 'cucumber rake task not available (cucumber not installed)'
+ task :cucumber do
+ abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem
or plugin'
end
+end
-end
\ No newline at end of file
+end
diff --git a/src/lib/tasks/demo_data.rake b/src/lib/tasks/demo_data.rake
index 8a58ede..4a32b3c 100644
--- a/src/lib/tasks/demo_data.rake
+++ b/src/lib/tasks/demo_data.rake
@@ -25,7 +25,7 @@ namespace :db do
SHORT_ACC = PROB_SHORT_REPONSE + PROB_FAILURE
MEDIUM_ACC = PROB_MEDIUM_RESPONSE + PROB_SHORT_REPONSE + PROB_FAILURE
- task :demo_data, :cloud_account_id, :user_id, :time_period, :number_of_tasks, :needs
=> :environment do |t, args|
+ task :demo_data, [:cloud_account_id, :user_id, :time_period, :number_of_tasks] =>
:environment do |t, args|
@time_scale = args[:time_period].to_f * 60 * 60
@number_of_tasks = args[:number_of_tasks]
diff --git a/src/lib/tasks/rspec.rake b/src/lib/tasks/rspec.rake
deleted file mode 100644
index 80d000d..0000000
--- a/src/lib/tasks/rspec.rake
+++ /dev/null
@@ -1,157 +0,0 @@
-gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9
-
-rspec_gem_dir = nil
-Dir["#{RAILS_ROOT}/vendor/gems/*"].each do |subdir|
- rspec_gem_dir = subdir if
subdir.gsub("#{RAILS_ROOT}/vendor/gems/","") =~ /^(\w+-)?rspec-(\d+)/
&& File.exist?("#{subdir}/lib/spec/rake/spectask.rb")
-end
-rspec_plugin_dir = File.expand_path(File.dirname(__FILE__) +
'/../../vendor/plugins/rspec')
-
-if rspec_gem_dir && (test ?d, rspec_plugin_dir)
- raise "\n#{'*'*50}\nYou have rspec installed in both vendor/gems and
vendor/plugins\nPlease pick one and dispose of the other.\n#{'*'*50}\n\n"
-end
-
-if rspec_gem_dir
- $LOAD_PATH.unshift("#{rspec_gem_dir}/lib")
-elsif File.exist?(rspec_plugin_dir)
- $LOAD_PATH.unshift("#{rspec_plugin_dir}/lib")
-end
-
-# Don't load rspec if running "rake gems:*"
-unless ARGV.any? {|a| a =~ /^gems/}
-
-begin
- require 'spec/rake/spectask'
-rescue MissingSourceFile
- module Spec
- module Rake
- class SpecTask
- 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.join(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('(a)tasks').delete('default')
-
-spec_prereq = File.exist?(File.join(RAILS_ROOT, 'config',
'database.yml')) ? "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)"
-Spec::Rake::SpecTask.new(:spec => spec_prereq) do |t|
- t.spec_opts = ['--options',
"\"#{RAILS_ROOT}/spec/spec.opts\""]
- t.spec_files = FileList['spec/**/*_spec.rb']
-end
-
-namespace :spec do
- desc "Run all specs in spec directory with RCov (excluding plugin specs)"
- Spec::Rake::SpecTask.new(:rcov) do |t|
- t.spec_opts = ['--options',
"\"#{RAILS_ROOT}/spec/spec.opts\""]
- t.spec_files = FileList['spec/**/*_spec.rb']
- t.rcov = true
- t.rcov_opts = lambda do
- IO.readlines("#{RAILS_ROOT}/spec/rcov.opts").map {|l| l.chomp.split
" "}.flatten
- end
- end
-
- desc "Prepare JUnit output rspec for Hudson"
- task :pre_junit do
- gem 'ci_reporter'
- require 'ci/reporter/rake/rspec'
- ENV["CI_REPORTS"] = 'hudson/reports/spec/'
- end
-
- desc "Run JUnit output filter for spec"
- task :junit => [:pre_junit, "ci:setup:rspec", "spec"]
-
- desc "Print Specdoc for all specs (excluding plugin specs)"
- Spec::Rake::SpecTask.new(:doc) do |t|
- t.spec_opts = ["--format", "specdoc", "--dry-run"]
- t.spec_files = FileList['spec/**/*_spec.rb']
- end
-
- desc "Print Specdoc for all plugin examples"
- Spec::Rake::SpecTask.new(:plugin_doc) do |t|
- t.spec_opts = ["--format", "specdoc", "--dry-run"]
- t.spec_files =
FileList['vendor/plugins/**/spec/**/*_spec.rb'].exclude('vendor/plugins/rspec/*')
- end
-
- [:models, :controllers, :views, :helpers, :lib, :integration].each do |sub|
- desc "Run the code examples in spec/#{sub}"
- Spec::Rake::SpecTask.new(sub => spec_prereq) do |t|
- t.spec_opts = ['--options',
"\"#{RAILS_ROOT}/spec/spec.opts\""]
- t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
- end
- end
-
- desc "Run the code examples in vendor/plugins (except RSpec's own)"
- Spec::Rake::SpecTask.new(:plugins => spec_prereq) do |t|
- t.spec_opts = ['--options',
"\"#{RAILS_ROOT}/spec/spec.opts\""]
- t.spec_files =
FileList['vendor/plugins/**/spec/**/*_spec.rb'].exclude('vendor/plugins/rspec/*').exclude("vendor/plugins/rspec-rails/*")
- end
-
- namespace :plugins do
- desc "Runs the examples for rspec_on_rails"
- Spec::Rake::SpecTask.new(:rspec_on_rails) do |t|
- t.spec_opts = ['--options',
"\"#{RAILS_ROOT}/spec/spec.opts\""]
- t.spec_files = FileList['vendor/plugins/rspec-rails/spec/**/*_spec.rb']
- end
- end
-
- # Setup specs for stats
- task :statsetup do
- require '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(Routing\ specs spec/routing) if
File.exist?('spec/routing')
- ::STATS_DIRECTORIES << %w(Integration\ specs spec/integration) if
File.exist?('spec/integration')
- ::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 << "Routing specs" if
File.exist?('spec/routing')
- ::CodeStatistics::TEST_TYPES << "Integration specs" if
File.exist?('spec/integration')
- end
-
- namespace :db do
- namespace :fixtures do
- desc "Load fixtures (from spec/fixtures) into the current environment's
database. Load specific fixtures using FIXTURES=x,y. Load from subdirectory in
test/fixtures using FIXTURES_DIR=z."
- task :load => :environment do
- ActiveRecord::Base.establish_connection(Rails.env)
- base_dir = File.join(Rails.root, 'spec', 'fixtures')
- fixtures_dir = ENV['FIXTURES_DIR'] ? File.join(base_dir,
ENV['FIXTURES_DIR']) : base_dir
-
- require 'active_record/fixtures'
- (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/).map {|f|
File.join(fixtures_dir, f) } : Dir.glob(File.join(fixtures_dir,
'*.{yml,csv}'))).each do |fixture_file|
- Fixtures.create_fixtures(File.dirname(fixture_file),
File.basename(fixture_file, '.*'))
- end
- end
- end
- end
-end
-
-end
-
-
diff --git a/src/spec/controllers/pools_controller_spec.rb
b/src/spec/controllers/pools_controller_spec.rb
index f5ee0cf..f9ec856 100644
--- a/src/spec/controllers/pools_controller_spec.rb
+++ b/src/spec/controllers/pools_controller_spec.rb
@@ -1,6 +1,7 @@
require 'spec_helper'
describe PoolsController do
+
fixtures :all
before(:each) do
@admin_permission = Factory :admin_permission
@@ -20,7 +21,7 @@ describe PoolsController do
response.should_not be_success
end
- it "should provider means to create new pool" do
+ it "should provide means to create new pool" do
UserSession.create(@admin)
lambda do
post :create, :pool => {
diff --git a/src/spec/controllers/user_sessions_controller_spec.rb
b/src/spec/controllers/user_sessions_controller_spec.rb
index b890b2e..33402bf 100644
--- a/src/spec/controllers/user_sessions_controller_spec.rb
+++ b/src/spec/controllers/user_sessions_controller_spec.rb
@@ -1,6 +1,7 @@
require 'spec_helper'
describe UserSessionsController do
+
fixtures :all
before(:each) do
@tuser = Factory :tuser
@@ -8,7 +9,7 @@ describe UserSessionsController do
end
it "should call new method" do
- route_for(:controller => 'user_sessions', :action =>
'new').should == 'login'
+ {:get => 'login'}.should route_to(:controller =>
'user_sessions', :action => 'new')
get :new
@current_user.should == nil
UserSession.find.should == nil
diff --git a/src/spec/controllers/users_controller_spec.rb
b/src/spec/controllers/users_controller_spec.rb
index 66bb50a..27d3037 100644
--- a/src/spec/controllers/users_controller_spec.rb
+++ b/src/spec/controllers/users_controller_spec.rb
@@ -2,6 +2,7 @@ require 'spec_helper'
describe UsersController do
+ fixtures :all
before(:each) do
@tuser = Factory :tuser
@admin_permission = Factory :admin_permission
diff --git a/src/spec/models/hardware_profile_spec.rb
b/src/spec/models/hardware_profile_spec.rb
index 1dcd0af..c3b26aa 100644
--- a/src/spec/models/hardware_profile_spec.rb
+++ b/src/spec/models/hardware_profile_spec.rb
@@ -205,4 +205,4 @@ describe HardwareProfile do
end
enum_set.should == value_array
end
-end
\ No newline at end of file
+end
diff --git a/src/spec/models/provider_spec.rb b/src/spec/models/provider_spec.rb
index 0771c9a..49914c6 100644
--- a/src/spec/models/provider_spec.rb
+++ b/src/spec/models/provider_spec.rb
@@ -4,7 +4,7 @@ require 'spec_helper'
describe Provider do
context "(using stubbed out connect method)" do
before(:each) do
- @client = mock('', :null_object => true)
+ @client = mock('DeltaCloud').as_null_object
@provider = Factory.build(:mock_provider)
@provider.stub!(:connect).and_return(@client)
end
@@ -47,7 +47,7 @@ describe Provider do
@provider.stub(:connect).and_return(nil)
deltacloud = @provider.connect
@provider.should have(1).error_on(:url)
- @provider.errors.on(:url).should eql("must be a valid provider url")
+ @provider.errors[:url].first.should eql("must be a valid provider url")
@provider.should_not be_valid
deltacloud.should be_nil
end
@@ -86,7 +86,7 @@ describe Provider do
context "(using original connect method)" do
it "should log errors when connecting to invalid url" do
- @logger = mock('Logger', :null_object => true)
+ @logger = mock('Logger').as_null_object
@provider = Factory.build(:mock_provider)
@provider.stub!(:logger).and_return(@logger)
diff --git a/src/spec/models/user_spec.rb b/src/spec/models/user_spec.rb
index acaba19..9637307 100644
--- a/src/spec/models/user_spec.rb
+++ b/src/spec/models/user_spec.rb
@@ -47,16 +47,16 @@ describe User do
u = Factory(:tuser)
u.first_name = ('a' * 256)
u.valid?.should be_false
- u.errors[:first_name].should_not be_nil
- u.errors[:first_name].should =~ /^is too long.*/
+ u.errors[:first_name].first.should_not be_nil
+ u.errors[:first_name].first.should =~ /^is too long.*/
end
it "should not be valid if last name is too long" do
u = Factory(:tuser)
u.last_name = ('a' * 256)
u.valid?.should be_false
- u.errors[:last_name].should_not be_nil
- u.errors[:last_name].should =~ /^is too long.*/
+ u.errors[:last_name].first.should_not be_nil
+ u.errors[:last_name].first.should =~ /^is too long.*/
end
it "should require quota to be set" do
diff --git a/src/spec/services/data_service_active_record_spec.rb
b/src/spec/services/data_service_active_record_spec.rb
index d108e01..2a8ff8f 100644
--- a/src/spec/services/data_service_active_record_spec.rb
+++ b/src/spec/services/data_service_active_record_spec.rb
@@ -3,7 +3,7 @@ require 'spec_helper'
describe DataServiceActiveRecord do
it "should calculate the total instance quota usage for a provider with a number
of cloud accounts" do
- client = mock('Conductor', :null_object => true)
+ client = mock('DeltaCloud').as_null_object
provider = Factory.build(:mock_provider)
provider.stub!(:connect).and_return(client)
provider.save!
@@ -29,7 +29,7 @@ describe DataServiceActiveRecord do
end
it "should calculate the total number of instances and maximum number of instances
of a cloud account" do
- client = mock('Conductor', :null_object => true)
+ client = mock('DeltaCloud').as_null_object
provider = Factory.build(:mock_provider)
provider.stub!(:connect).and_return(client)
provider.save!
@@ -121,7 +121,7 @@ describe DataServiceActiveRecord do
end_time = Time.utc(2010,"jan",1,20,15,1)
start_time = end_time - (interval_length * no_intervals)
- client = mock('Conductor', :null_object => true)
+ client = mock('DeltaCloud').as_null_object
provider = Factory.build(:mock_provider)
provider.stub!(:connect).and_return(client)
provider.save!
diff --git a/src/spec/services/registration_service_spec.rb
b/src/spec/services/registration_service_spec.rb
index 222d028..dfc59ed 100644
--- a/src/spec/services/registration_service_spec.rb
+++ b/src/spec/services/registration_service_spec.rb
@@ -2,6 +2,7 @@ require 'spec_helper'
describe RegistrationService do
+ fixtures :all
before(:each) do
end
@@ -14,7 +15,7 @@ describe RegistrationService do
r.save.should be_false
user.errors.empty?.should be_false
user.errors.find_all do |attr,msg|
-
["email","password","password_confirmation"].include?(attr).should
be_true
+ [:email, :password, :password_confirmation].include?(attr).should be_true
end
end
diff --git a/src/spec/spec.opts b/src/spec/spec.opts
deleted file mode 100644
index 391705b..0000000
--- a/src/spec/spec.opts
+++ /dev/null
@@ -1,4 +0,0 @@
---colour
---format progress
---loadby mtime
---reverse
diff --git a/src/spec/spec_helper.rb b/src/spec/spec_helper.rb
index ff6bde2..97aca3e 100644
--- a/src/spec/spec_helper.rb
+++ b/src/spec/spec_helper.rb
@@ -1,52 +1,22 @@
-# This file is copied to ~/spec when you run 'ruby script/generate rspec'
-# from the project root directory.
+# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
-require
File.expand_path(File.join(File.dirname(__FILE__),'..','config','environment'))
-require 'spec/autorun'
-require 'spec/rails'
+require File.expand_path("../../config/environment", __FILE__)
+require 'rspec/rails'
require 'authlogic/test_case'
require 'timecop'
require 'database_cleaner'
require 'vcr_setup'
-# Uncomment the next line to use webrat's matchers
-#require 'webrat/integrations/rspec-rails'
+# Requires supporting ruby files with custom matchers and macros, etc,
+# in spec/support/ and its subdirectories.
+Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
-# Requires supporting files with custom matchers and macros, etc,
-# in ./support/ and its subdirectories.
-Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each
{|f| require f}
-
-Spec::Runner.configure do |config|
- # If you're not using ActiveRecord you should remove these
- # lines, delete config/database.yml and disable :active_record
- # in your config/boot.rb
- config.use_transactional_fixtures = true
- config.use_instantiated_fixtures = false
- config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
-
- # == Fixtures
- #
- # You can declare fixtures for each example_group like this:
- # describe "...." do
- # fixtures :table_a, :table_b
- #
- # Alternatively, if you prefer to declare them only once, you can
- # do so right here. Just uncomment the next line and replace the fixture
- # names with your fixtures.
- #
- # 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.
- #
- # You can also declare which fixtures to use (for example fixtures for test/fixtures):
- #
- # config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
+RSpec.configure do |config|
+ include Authlogic::TestCase
#
# == Mock Framework
#
- # RSpec uses its own mocking framework by default. If you prefer to
- # use mocha, flexmock or RR, uncomment the appropriate line:
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
--
1.7.4.4