This patch is intended to fix only the case listed in $subject, specifically in the non-bundler setup (though it should certainly cause far fewer fails with no services running under bundler as well). Note that I had to make somewhat of a temprary fix due to time constraints, which is noted as such in the spec_helper. If you run specs from system gems before this patch, and turns off the deltacloud service, you wil get in the vicinity of 180-some-odd failures. After the patch you should get 0. I plan to keep poking at this next week, but that will miss code freeze. My plan is to try to sneak in fixes for the 3 or so remaining fails that are caused when iwhd is not running, and to see why controllers fail without the above-mentioned temporary fix in spec_helper.
I noticed a couple major issues that need some though (and hopefully will at least partly be covered by upcoming arch improvements, pending list discussion): * Our code is _really_ intertwined in a number of areas. This makes for a tough row to hoe with some of the tests. When a developer has to dig through 4-6 different models to figure out what needs to be stubbed to get a single model's tests passing, that is a _bad thing(tm)_. We need better encapsulation of our code. * A number of our controller tests are actually testing the model behavior, which is flat out wrong. Test models in model specs. Controller specs should _only_ be testing against mock_models and verifying things like 'method called', variable set, etc. Otherwise you are testing business logic in the wrong place.
-j
https://www.aeolusproject.org/redmine/issues/3438 --- src/app/models/deployment.rb | 7 +---- src/app/models/provider.rb | 9 +------ .../controllers/pool_families_controller_spec.rb | 4 ++- src/spec/controllers/providers_controller_spec.rb | 21 ++++++++------- src/spec/factories/instance.rb | 1 - src/spec/factories/provider.rb | 4 +++ src/spec/factories/provider_account.rb | 1 + src/spec/models/deployment_spec.rb | 4 +- src/spec/models/instance_spec.rb | 12 +++----- src/spec/models/provider_account_spec.rb | 8 +++--- src/spec/models/provider_spec.rb | 6 +++- src/spec/spec_helper.rb | 27 +++++++++++++++++--- 12 files changed, 59 insertions(+), 45 deletions(-)
diff --git a/src/app/models/deployment.rb b/src/app/models/deployment.rb index 3ad7863..202f960 100644 --- a/src/app/models/deployment.rb +++ b/src/app/models/deployment.rb @@ -179,12 +179,7 @@ class Deployment < ActiveRecord::Base # stop all deployment's instances instances.each do |instance| next unless instance.state == Instance::STATE_RUNNING - - @task = instance.queue_action(instance.owner, 'stop') - unless @task - raise I18n.t("deployments.errors.cannot_stop") - end - Taskomatic.stop_instance(@task) + instance.stop(instance.owner) end else raise I18n.t("deployments.errors.all_stopped") diff --git a/src/app/models/provider.rb b/src/app/models/provider.rb index fe9ab97..cf2a7e7 100644 --- a/src/app/models/provider.rb +++ b/src/app/models/provider.rb @@ -239,14 +239,7 @@ class Provider < ActiveRecord::Base errs = [] stoppable_instances.each do |instance| begin - unless instance.valid_action?('stop') - raise "stop is an invalid action." - end - - unless @task = instance.queue_action(user, 'stop') - raise "stop cannot be performed on this instance." - end - Taskomatic.stop_instance(@task) + instance.stop(user) rescue Exception => e err = "Error while stopping an instance #{instance.name}: #{e.message}" errs << err diff --git a/src/spec/controllers/pool_families_controller_spec.rb b/src/spec/controllers/pool_families_controller_spec.rb index b913d6a..c90f006 100644 --- a/src/spec/controllers/pool_families_controller_spec.rb +++ b/src/spec/controllers/pool_families_controller_spec.rb @@ -52,11 +52,13 @@ describe PoolFamiliesController do it "should allow authorized users to edit pool family" do pool_family = FactoryGirl.create :pool_family mock_warden(@admin) + family = mock_model(PoolFamily).as_null_object + PoolFamily.stub(:find).and_return(family) put :update, :id => pool_family.id, :pool_family => { :name => 'updated pool family', :quota_attributes => { :maximum_running_instances => 10 }, } - PoolFamily.find_by_name('updated pool family').should_not be_nil + flash[:notice].should eq(I18n.t("pool_families.flash.notice.updated")) response.should redirect_to(pool_families_path) end
diff --git a/src/spec/controllers/providers_controller_spec.rb b/src/spec/controllers/providers_controller_spec.rb index 38228fb..d86fcc9 100644 --- a/src/spec/controllers/providers_controller_spec.rb +++ b/src/spec/controllers/providers_controller_spec.rb @@ -94,17 +94,18 @@ describe ProvidersController do end
describe "check availability" do - context "when provider is not accessible" do - before do - @provider.update_attribute(:url, "invalid_url") - end + let(:p) { mock_model(Provider).as_null_object } + before do + Provider.stub(:find).and_return(p) + end
- it "should update availability status on test connection" do - @provider.available.should_not be_false - get :edit, :id => @provider.id, :test_provider => true - @provider.reload - @provider.available.should be_false - end + it "should update availability status on test connection" do + p.should_receive(:update_availability) + get :edit, :id => @provider.id, :test_provider => true + end + it "should set a flash message" do + get :edit, :id => @provider.id, :test_provider => true + flash.should_not be_empty end end
diff --git a/src/spec/factories/instance.rb b/src/spec/factories/instance.rb index 9675df4..7b2fa54 100644 --- a/src/spec/factories/instance.rb +++ b/src/spec/factories/instance.rb @@ -62,5 +62,4 @@ FactoryGirl.define do factory :instance_in_disabled_pool, :parent => :new_instance do association :pool, :factory => :disabled_pool end - end diff --git a/src/spec/factories/provider.rb b/src/spec/factories/provider.rb index e603934..f41e752 100644 --- a/src/spec/factories/provider.rb +++ b/src/spec/factories/provider.rb @@ -20,6 +20,10 @@ FactoryGirl.define do sequence(:name) { |n| "provider#{n}" } provider_type { Factory.build :provider_type } url { |p| "http://www." + p.name + ".com/api" } + after_build do |p| + p.stub(:valid_framework?).and_return(true) + p.stub(:valid_provider?).and_return(true) + end end
factory :mock_provider, :parent => :provider do diff --git a/src/spec/factories/provider_account.rb b/src/spec/factories/provider_account.rb index 93afc12..cc87b8b 100644 --- a/src/spec/factories/provider_account.rb +++ b/src/spec/factories/provider_account.rb @@ -26,6 +26,7 @@ FactoryGirl.define do after_build do |acc| acc.credentials << Factory.build(:username_credential) acc.credentials << Factory.build(:password_credential) + acc.pool_families << PoolFamily.find_by_name('default') end end
diff --git a/src/spec/models/deployment_spec.rb b/src/spec/models/deployment_spec.rb index c996d51..da893d2 100644 --- a/src/spec/models/deployment_spec.rb +++ b/src/spec/models/deployment_spec.rb @@ -118,7 +118,7 @@ describe Deployment do inst2.save! inst3 = Factory.create :mock_running_instance, :deployment_id => @deployment.id @deployment.reload - Taskomatic.stub!(:stop_instance).and_return(nil) + Instance.any_instance.stub(:get_action_list).and_return(['stop']) @deployment.stop_instances_and_destroy! inst1.tasks.last.action.should == 'stop' inst3.tasks.last.action.should == 'stop' @@ -341,7 +341,7 @@ describe Deployment do inst1 = Factory.create :mock_running_instance, :deployment_id => @deployment.id inst2 = Factory.create :mock_running_instance, :deployment_id => @deployment.id @deployment.reload - + Instance.any_instance.stub(:get_action_list).and_return(['stop']) @deployment.stop_instances_and_destroy! inst1.reload inst2.reload diff --git a/src/spec/models/instance_spec.rb b/src/spec/models/instance_spec.rb index 8ffaf4c..87dd77d 100644 --- a/src/spec/models/instance_spec.rb +++ b/src/spec/models/instance_spec.rb @@ -110,10 +110,6 @@ describe Instance do @instance.valid_action?('start').should == true end
- it "should return action list" do - @instance.get_action_list.should eql(["reboot", "stop"]) - end - it "should be able to queue new actions" do @instance.stub!(:get_action_list).and_return(@actions) user = User.new @@ -240,9 +236,10 @@ describe Instance do end
it "shouldn't match provider accounts where image is not pushed" do - account2 = FactoryGirl.create(:mock_provider_account2, :label => 'testaccount') - @pool.pool_family.provider_accounts = [account2] - @instance.matches.last.should include(I18n.t('instances.errors.image_not_pushed_to_provider', :account_name => 'testaccount')) + inst = Factory.create(:new_instance) + inst.stub(:image_build).and_return("foo") + inst.stub(:provider_images_for_match).and_return([]) + inst.matches.last.should include(I18n.t('instances.errors.image_not_pushed_to_provider', :account_name => inst.provider_account.name)) end
it "shouldn't match provider accounts where matching hardware profile not found" do @@ -325,6 +322,7 @@ describe Instance do it "should not be launchable if its pool's providers are all disabled" do instance = FactoryGirl.build(:instance) instance.pool.pool_family.provider_accounts << FactoryGirl.create(:disabled_provider_account) + instance.pool.pool_family.stub(:all_providers_disabled?).and_return(true) instance.should_not be_valid instance.errors[:pool].should_not be_empty instance.errors[:pool].first.should == I18n.t('pools.errors.providers_disabled') diff --git a/src/spec/models/provider_account_spec.rb b/src/spec/models/provider_account_spec.rb index a8c1074..5e212b8 100644 --- a/src/spec/models/provider_account_spec.rb +++ b/src/spec/models/provider_account_spec.rb @@ -46,12 +46,13 @@ describe ProviderAccount do
invalid_provider_account = Factory.build(:mock_provider_account, :provider => mock_provider) invalid_provider_account.credentials_hash = {'username' => "wrong_username", 'password' => "wrong_password"} + invalid_provider_account.stub(:valid_credentials?).and_return(false) invalid_provider_account.should_not be_valid
ec2_provider = FactoryGirl.create :ec2_provider invalid_ec2_provider_account = Factory.build(:ec2_provider_account, :provider => ec2_provider) invalid_ec2_provider_account.credentials_hash = {'username' => "", 'password' => nil} - invalid_ec2_provider_account.valid_credentials?.should == false + invalid_ec2_provider_account.stub(:valid_credentials?).and_return(false) invalid_ec2_provider_account.should_not be_valid
valid_provider_account = Factory.build(:mock_provider_account, :provider => mock_provider) @@ -61,13 +62,14 @@ describe ProviderAccount do it "should fail to create a cloud account if the provider credentials are invalid" do provider_account = Factory.build(:mock_provider_account) provider_account.credentials_hash = {'password' => "wrong_password"} + provider_account.stub(:valid_credentials?).and_return(false) provider_account.save.should == false end
it "should add errors when testing credentials fails" do provider_account = Factory.build(:mock_provider_account) provider_account.credentials_hash = {'password' => "wrong_password"} - provider_account.stub(:valid_credentials).and_raise("DeltacloudError") + provider_account.stub(:valid_credentials?).and_raise("DeltacloudError") provider_account.save.should == false provider_account.errors[:base].should == [I18n.t('provider_accounts.errors.exception_while_validating')] end @@ -85,8 +87,6 @@ describe ProviderAccount do end
it "when calling connect and it fails with exception it will return nil" do - DeltaCloud.should_receive(:new).and_raise(Exception.new) - @provider_account.connect.should be_nil end
diff --git a/src/spec/models/provider_spec.rb b/src/spec/models/provider_spec.rb index a59fafe..dac9da2 100644 --- a/src/spec/models/provider_spec.rb +++ b/src/spec/models/provider_spec.rb @@ -57,9 +57,9 @@ describe Provider do end
it "should set error if unable to connect to specified deltacloud instance" do - @provider.stub(:valid_provider?).and_return(true) @provider.url = "http://invalid.provider/url" @provider.stub(:connect).and_return(nil) + @provider.stub(:valid_framework?).and_return(false) @provider.should have(1).error_on(:url) @provider.errors[:url].first.should eql(I18n.t("activerecord.errors.models.provider.attributes.url.invalid_framework")) @provider.should_not be_valid @@ -100,6 +100,7 @@ describe Provider do pa = FactoryGirl.create(:mock_provider_account, :provider => provider1) inst1 = FactoryGirl.create(:instance, :provider_account => pa) inst2 = FactoryGirl.create(:instance, :provider_account => pa) + Instance.any_instance.stub(:stop).and_return(nil) errs = provider1.disable(nil)[:failed_to_stop] errs.should be_empty end @@ -108,7 +109,7 @@ describe Provider do provider1 = Factory.create(:mock_provider) pa = FactoryGirl.create(:mock_provider_account, :provider => provider1) inst1 = FactoryGirl.create(:instance, :provider_account => pa) - Instance.any_instance.stub(:valid_action?).and_return(false) + Instance.any_instance.stub(:stop).and_raise errs = provider1.disable(nil)[:failed_to_stop] errs.should_not be_empty provider1.enabled.should be_true @@ -147,6 +148,7 @@ describe Provider do
it "should mark provider as unavailable if inaccessible" do @provider.available.should be_true + @provider.stub(:valid_framework?).and_return(false) @provider.populate_realms @provider.available.should be_false end diff --git a/src/spec/spec_helper.rb b/src/spec/spec_helper.rb index ffaf879..e7bcf96 100644 --- a/src/spec/spec_helper.rb +++ b/src/spec/spec_helper.rb @@ -65,6 +65,29 @@ def mock_warden(user) SessionEntity.update_session(@session_id, user) if user end
+# Without these here, controller specs fail. These 2 class_evals can +# be removed once stubs work and/or are added to the right place. +Provider.class_eval do + def valid_framework? + true + end + + def valid_provider? + true + end +end + +ProviderAccount.class_eval do + + def connect + nil + end + + def valid_credentials? + true + end +end + RSpec.configure do |config| config.use_transactional_fixtures = true config.use_instantiated_fixtures = false @@ -88,10 +111,6 @@ RSpec.configure do |config| # activate_authlogic #end
- config.before(:each) do - Provider.any_instance.stub(:valid_provider?).and_return(true) - Provider.any_instance.stub(:valid_famework?).and_return(true) - end #config.after(:each, :type => :controller) do # current_user_session.destroy #end
On 06/29/2012 12:53 PM, Jason Guiditta wrote:
https://www.aeolusproject.org/redmine/issues/3438
src/app/models/deployment.rb | 7 +---- src/app/models/provider.rb | 9 +------ .../controllers/pool_families_controller_spec.rb | 4 ++- src/spec/controllers/providers_controller_spec.rb | 21 ++++++++------- src/spec/factories/instance.rb | 1 - src/spec/factories/provider.rb | 4 +++ src/spec/factories/provider_account.rb | 1 + src/spec/models/deployment_spec.rb | 4 +- src/spec/models/instance_spec.rb | 12 +++----- src/spec/models/provider_account_spec.rb | 8 +++--- src/spec/models/provider_spec.rb | 6 +++- src/spec/spec_helper.rb | 27 +++++++++++++++++--- 12 files changed, 59 insertions(+), 45 deletions(-)
diff --git a/src/app/models/deployment.rb b/src/app/models/deployment.rb index 3ad7863..202f960 100644 --- a/src/app/models/deployment.rb +++ b/src/app/models/deployment.rb @@ -179,12 +179,7 @@ class Deployment < ActiveRecord::Base # stop all deployment's instances instances.each do |instance| next unless instance.state == Instance::STATE_RUNNING
@task = instance.queue_action(instance.owner, 'stop')unless @taskraise I18n.t("deployments.errors.cannot_stop")endTaskomatic.stop_instance(@task)
instance.stop(instance.owner) end else raise I18n.t("deployments.errors.all_stopped")diff --git a/src/app/models/provider.rb b/src/app/models/provider.rb index fe9ab97..cf2a7e7 100644 --- a/src/app/models/provider.rb +++ b/src/app/models/provider.rb @@ -239,14 +239,7 @@ class Provider < ActiveRecord::Base errs = [] stoppable_instances.each do |instance| begin
unless instance.valid_action?('stop')raise "stop is an invalid action."endunless @task = instance.queue_action(user, 'stop')raise "stop cannot be performed on this instance."endTaskomatic.stop_instance(@task)
instance.stop(user) rescue Exception => e err = "Error while stopping an instance #{instance.name}: #{e.message}" errs << errdiff --git a/src/spec/controllers/pool_families_controller_spec.rb b/src/spec/controllers/pool_families_controller_spec.rb index b913d6a..c90f006 100644 --- a/src/spec/controllers/pool_families_controller_spec.rb +++ b/src/spec/controllers/pool_families_controller_spec.rb @@ -52,11 +52,13 @@ describe PoolFamiliesController do it "should allow authorized users to edit pool family" do pool_family = FactoryGirl.create :pool_family mock_warden(@admin)
- family = mock_model(PoolFamily).as_null_object
- PoolFamily.stub(:find).and_return(family) put :update, :id => pool_family.id, :pool_family => { :name => 'updated pool family', :quota_attributes => { :maximum_running_instances => 10 }, }
- PoolFamily.find_by_name('updated pool family').should_not be_nil
- flash[:notice].should eq(I18n.t("pool_families.flash.notice.updated")) response.should redirect_to(pool_families_path) end
diff --git a/src/spec/controllers/providers_controller_spec.rb b/src/spec/controllers/providers_controller_spec.rb index 38228fb..d86fcc9 100644 --- a/src/spec/controllers/providers_controller_spec.rb +++ b/src/spec/controllers/providers_controller_spec.rb @@ -94,17 +94,18 @@ describe ProvidersController do end
describe "check availability" do
context "when provider is not accessible" dobefore do@provider.update_attribute(:url, "invalid_url")end
let(:p) { mock_model(Provider).as_null_object }before doProvider.stub(:find).and_return(p)end
it "should update availability status on test connection" do@provider.available.should_not be_falseget :edit, :id => @provider.id, :test_provider => true@provider.reload@provider.available.should be_falseend
it "should update availability status on test connection" dop.should_receive(:update_availability)get :edit, :id => @provider.id, :test_provider => trueendit "should set a flash message" doget :edit, :id => @provider.id, :test_provider => trueflash.should_not be_empty end enddiff --git a/src/spec/factories/instance.rb b/src/spec/factories/instance.rb index 9675df4..7b2fa54 100644 --- a/src/spec/factories/instance.rb +++ b/src/spec/factories/instance.rb @@ -62,5 +62,4 @@ FactoryGirl.define do factory :instance_in_disabled_pool, :parent => :new_instance do association :pool, :factory => :disabled_pool end
- end
diff --git a/src/spec/factories/provider.rb b/src/spec/factories/provider.rb index e603934..f41e752 100644 --- a/src/spec/factories/provider.rb +++ b/src/spec/factories/provider.rb @@ -20,6 +20,10 @@ FactoryGirl.define do sequence(:name) { |n| "provider#{n}" } provider_type { Factory.build :provider_type } url { |p| "http://www." + p.name + ".com/api" }
after_build do |p|
p.stub(:valid_framework?).and_return(true)p.stub(:valid_provider?).and_return(true)end end
factory :mock_provider, :parent => :provider do
diff --git a/src/spec/factories/provider_account.rb b/src/spec/factories/provider_account.rb index 93afc12..cc87b8b 100644 --- a/src/spec/factories/provider_account.rb +++ b/src/spec/factories/provider_account.rb @@ -26,6 +26,7 @@ FactoryGirl.define do after_build do |acc| acc.credentials << Factory.build(:username_credential) acc.credentials << Factory.build(:password_credential)
endacc.pool_families << PoolFamily.find_by_name('default') enddiff --git a/src/spec/models/deployment_spec.rb b/src/spec/models/deployment_spec.rb index c996d51..da893d2 100644 --- a/src/spec/models/deployment_spec.rb +++ b/src/spec/models/deployment_spec.rb @@ -118,7 +118,7 @@ describe Deployment do inst2.save! inst3 = Factory.create :mock_running_instance, :deployment_id => @deployment.id @deployment.reload
Taskomatic.stub!(:stop_instance).and_return(nil)
Instance.any_instance.stub(:get_action_list).and_return(['stop']) @deployment.stop_instances_and_destroy! inst1.tasks.last.action.should == 'stop' inst3.tasks.last.action.should == 'stop'@@ -341,7 +341,7 @@ describe Deployment do inst1 = Factory.create :mock_running_instance, :deployment_id => @deployment.id inst2 = Factory.create :mock_running_instance, :deployment_id => @deployment.id @deployment.reload
Instance.any_instance.stub(:get_action_list).and_return(['stop']) @deployment.stop_instances_and_destroy! inst1.reload inst2.reloaddiff --git a/src/spec/models/instance_spec.rb b/src/spec/models/instance_spec.rb index 8ffaf4c..87dd77d 100644 --- a/src/spec/models/instance_spec.rb +++ b/src/spec/models/instance_spec.rb @@ -110,10 +110,6 @@ describe Instance do @instance.valid_action?('start').should == true end
- it "should return action list" do
- @instance.get_action_list.should eql(["reboot", "stop"])
- end
- it "should be able to queue new actions" do @instance.stub!(:get_action_list).and_return(@actions) user = User.new
@@ -240,9 +236,10 @@ describe Instance do end
it "shouldn't match provider accounts where image is not pushed" do
- account2 = FactoryGirl.create(:mock_provider_account2, :label => 'testaccount')
- @pool.pool_family.provider_accounts = [account2]
- @instance.matches.last.should include(I18n.t('instances.errors.image_not_pushed_to_provider', :account_name => 'testaccount'))
inst = Factory.create(:new_instance)
inst.stub(:image_build).and_return("foo")
inst.stub(:provider_images_for_match).and_return([])
inst.matches.last.should include(I18n.t('instances.errors.image_not_pushed_to_provider', :account_name => inst.provider_account.name)) end
it "shouldn't match provider accounts where matching hardware profile not found" do
@@ -325,6 +322,7 @@ describe Instance do it "should not be launchable if its pool's providers are all disabled" do instance = FactoryGirl.build(:instance) instance.pool.pool_family.provider_accounts << FactoryGirl.create(:disabled_provider_account)
- instance.pool.pool_family.stub(:all_providers_disabled?).and_return(true) instance.should_not be_valid instance.errors[:pool].should_not be_empty instance.errors[:pool].first.should == I18n.t('pools.errors.providers_disabled')
diff --git a/src/spec/models/provider_account_spec.rb b/src/spec/models/provider_account_spec.rb index a8c1074..5e212b8 100644 --- a/src/spec/models/provider_account_spec.rb +++ b/src/spec/models/provider_account_spec.rb @@ -46,12 +46,13 @@ describe ProviderAccount do
invalid_provider_account = Factory.build(:mock_provider_account, :provider => mock_provider) invalid_provider_account.credentials_hash = {'username' => "wrong_username", 'password' => "wrong_password"}
invalid_provider_account.stub(:valid_credentials?).and_return(false) invalid_provider_account.should_not be_valid
ec2_provider = FactoryGirl.create :ec2_provider invalid_ec2_provider_account = Factory.build(:ec2_provider_account, :provider => ec2_provider) invalid_ec2_provider_account.credentials_hash = {'username' => "", 'password' => nil}
- invalid_ec2_provider_account.valid_credentials?.should == false
invalid_ec2_provider_account.stub(:valid_credentials?).and_return(false) invalid_ec2_provider_account.should_not be_valid
valid_provider_account = Factory.build(:mock_provider_account, :provider => mock_provider)
@@ -61,13 +62,14 @@ describe ProviderAccount do it "should fail to create a cloud account if the provider credentials are invalid" do provider_account = Factory.build(:mock_provider_account) provider_account.credentials_hash = {'password' => "wrong_password"}
provider_account.stub(:valid_credentials?).and_return(false) provider_account.save.should == false end
it "should add errors when testing credentials fails" do provider_account = Factory.build(:mock_provider_account) provider_account.credentials_hash = {'password' => "wrong_password"}
- provider_account.stub(:valid_credentials).and_raise("DeltacloudError")
- provider_account.stub(:valid_credentials?).and_raise("DeltacloudError") provider_account.save.should == false provider_account.errors[:base].should == [I18n.t('provider_accounts.errors.exception_while_validating')] end
@@ -85,8 +87,6 @@ describe ProviderAccount do end
it "when calling connect and it fails with exception it will return nil" do
- DeltaCloud.should_receive(:new).and_raise(Exception.new)
end@provider_account.connect.should be_nildiff --git a/src/spec/models/provider_spec.rb b/src/spec/models/provider_spec.rb index a59fafe..dac9da2 100644 --- a/src/spec/models/provider_spec.rb +++ b/src/spec/models/provider_spec.rb @@ -57,9 +57,9 @@ describe Provider do end
it "should set error if unable to connect to specified deltacloud instance" do
@provider.stub(:valid_provider?).and_return(true) @provider.url = "http://invalid.provider/url" @provider.stub(:connect).and_return(nil)
@provider.stub(:valid_framework?).and_return(false) @provider.should have(1).error_on(:url) @provider.errors[:url].first.should eql(I18n.t("activerecord.errors.models.provider.attributes.url.invalid_framework")) @provider.should_not be_valid@@ -100,6 +100,7 @@ describe Provider do pa = FactoryGirl.create(:mock_provider_account, :provider => provider1) inst1 = FactoryGirl.create(:instance, :provider_account => pa) inst2 = FactoryGirl.create(:instance, :provider_account => pa)
Instance.any_instance.stub(:stop).and_return(nil) errs = provider1.disable(nil)[:failed_to_stop] errs.should be_empty end@@ -108,7 +109,7 @@ describe Provider do provider1 = Factory.create(:mock_provider) pa = FactoryGirl.create(:mock_provider_account, :provider => provider1) inst1 = FactoryGirl.create(:instance, :provider_account => pa)
Instance.any_instance.stub(:valid_action?).and_return(false)
Instance.any_instance.stub(:stop).and_raise errs = provider1.disable(nil)[:failed_to_stop] errs.should_not be_empty provider1.enabled.should be_true@@ -147,6 +148,7 @@ describe Provider do
it "should mark provider as unavailable if inaccessible" do @provider.available.should be_true
@provider.stub(:valid_framework?).and_return(false) @provider.populate_realms @provider.available.should be_false enddiff --git a/src/spec/spec_helper.rb b/src/spec/spec_helper.rb index ffaf879..e7bcf96 100644 --- a/src/spec/spec_helper.rb +++ b/src/spec/spec_helper.rb @@ -65,6 +65,29 @@ def mock_warden(user) SessionEntity.update_session(@session_id, user) if user end
+# Without these here, controller specs fail. These 2 class_evals can +# be removed once stubs work and/or are added to the right place. +Provider.class_eval do
- def valid_framework?
- true
- end
- def valid_provider?
- true
- end
+end
+ProviderAccount.class_eval do
- def connect
- nil
- end
- def valid_credentials?
- true
- end
+end
- RSpec.configure do |config| config.use_transactional_fixtures = true config.use_instantiated_fixtures = false
@@ -88,10 +111,6 @@ RSpec.configure do |config| # activate_authlogic #end
- config.before(:each) do
- Provider.any_instance.stub(:valid_provider?).and_return(true)
- Provider.any_instance.stub(:valid_famework?).and_return(true)
- end #config.after(:each, :type => :controller) do # current_user_session.destroy #end
Acked and pushed.
aeolus-devel@lists.fedorahosted.org