Skip to content

Commit

Permalink
Remove warning when tests are executed
Browse files Browse the repository at this point in the history
Reasons:
 - This message appears when running "bundle exec rake spec".
WARNING: Shared example group '#validate!' has been previously defined at:
  /home/got/projects/ruby/knife-openstack/spec/unit/validate_spec.rb:20
...and you are now defining it at:
  /home/got/projects/ruby/knife-openstack/spec/unit/validate_spec.rb:20
The new definition will overwrite the original one.

Changes:
 - Move shared_context declarations into spec_context.rb
 - Load shared context into spec_helper
PierreRambaud committed Mar 4, 2015
1 parent a323bfe commit a574d52
Showing 9 changed files with 5 additions and 13 deletions.
2 changes: 0 additions & 2 deletions spec/unit/validate_spec.rb → spec/spec_context.rb
Original file line number Diff line number Diff line change
@@ -15,8 +15,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

require 'spec_helper'

shared_context "#validate!" do |instance|
before(:each) do
Chef::Config[:knife][:openstack_username] = "testuser"
7 changes: 4 additions & 3 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@
require 'resource_spec_helper'
require 'server_command_common_spec_helper'
require 'tempfile'
require 'spec_context'

def find_instance_id(instance_name, file)
file.lines.each do |line|
@@ -61,7 +62,7 @@ def is_config_present
err_msg = "\nPlease set #{unset_env_var.join(', ')} environment"
err_msg = err_msg + ( unset_env_var.length > 1 ? " variables " : " variable " ) + "for integration tests."
puts err_msg unless unset_env_var.empty?

%w(OS_SSH_USER OPENSTACK_PRI_KEY OPENSTACK_KEY_PAIR OS_WINDOWS_SSH_USER OS_WINDOWS_SSH_PASSWORD OS_WINRM_USER OS_WINRM_PASSWORD OS_LINUX_IMAGE OS_LINUX_FLAVOR OS_INVALID_FLAVOR OS_INVALID_FLOATING_IP OS_WINDOWS_FLAVOR OS_WINDOWS_IMAGE OS_WINDOWS_SSH_IMAGE OS_NETWORK_IDS OS_AVAILABILITY_ZONE).each do |os_config_opt|
option_value = ENV[os_config_opt] || (openstack_config[os_config_opt] if openstack_config)
if option_value.nil?
@@ -73,7 +74,7 @@ def is_config_present
config_err_msg = "\nPlease set #{unset_config_options.join(', ')} config"
config_err_msg = config_err_msg + ( unset_config_options.length > 1 ? " options in ../spec/integration/config/environment.yml or as environment variables" : " option in ../spec/integration/config/environment.yml or as environment variable" ) + " for integration tests."
puts config_err_msg unless unset_config_options.empty?

is_config
end

@@ -127,4 +128,4 @@ def create_sh_user_data_file
def delete_sh_user_data_file(file)
file.close
file.unlink
end
end
1 change: 0 additions & 1 deletion spec/unit/openstack_flavor_list_spec.rb
Original file line number Diff line number Diff line change
@@ -21,7 +21,6 @@
require 'chef/knife/openstack_flavor_list'
require 'chef/knife/cloud/openstack_service'
require 'support/shared_examples_for_command'
require 'unit/validate_spec'

describe Chef::Knife::Cloud::OpenstackFlavorList do
it_behaves_like Chef::Knife::Cloud::Command, Chef::Knife::Cloud::OpenstackFlavorList.new
1 change: 0 additions & 1 deletion spec/unit/openstack_group_list_spec.rb
Original file line number Diff line number Diff line change
@@ -21,7 +21,6 @@
require 'chef/knife/openstack_group_list'
require 'chef/knife/cloud/openstack_service'
require 'support/shared_examples_for_command'
require 'unit/validate_spec'

describe Chef::Knife::Cloud::OpenstackGroupList do
it_behaves_like Chef::Knife::Cloud::Command, Chef::Knife::Cloud::OpenstackGroupList.new
1 change: 0 additions & 1 deletion spec/unit/openstack_image_list_spec.rb
Original file line number Diff line number Diff line change
@@ -21,7 +21,6 @@
require 'chef/knife/openstack_image_list'
require 'chef/knife/cloud/openstack_service'
require 'support/shared_examples_for_command'
require 'unit/validate_spec'

describe Chef::Knife::Cloud::OpenstackImageList do
it_behaves_like Chef::Knife::Cloud::Command, Chef::Knife::Cloud::OpenstackImageList.new
1 change: 0 additions & 1 deletion spec/unit/openstack_network_list_spec.rb
Original file line number Diff line number Diff line change
@@ -20,7 +20,6 @@
require 'chef/knife/openstack_network_list'
require 'chef/knife/cloud/openstack_service'
require 'support/shared_examples_for_command'
require 'unit/validate_spec'

describe Chef::Knife::Cloud::OpenstackNetworkList do
it_behaves_like Chef::Knife::Cloud::Command, Chef::Knife::Cloud::OpenstackNetworkList.new
1 change: 0 additions & 1 deletion spec/unit/openstack_server_delete_spec.rb
Original file line number Diff line number Diff line change
@@ -22,7 +22,6 @@
require 'chef/knife/openstack_server_delete'
require 'chef/knife/cloud/openstack_service'
require 'support/shared_examples_for_serverdeletecommand'
require 'unit/validate_spec'

describe Chef::Knife::Cloud::OpenstackServerDelete do
it_behaves_like Chef::Knife::Cloud::ServerDeleteCommand, Chef::Knife::Cloud::OpenstackServerDelete.new
1 change: 0 additions & 1 deletion spec/unit/openstack_server_list_spec.rb
Original file line number Diff line number Diff line change
@@ -21,7 +21,6 @@
require 'chef/knife/openstack_server_list'
require 'chef/knife/cloud/openstack_service'
require 'support/shared_examples_for_command'
require 'unit/validate_spec'

describe Chef::Knife::Cloud::OpenstackServerList do
it_behaves_like Chef::Knife::Cloud::Command, Chef::Knife::Cloud::OpenstackServerList.new
3 changes: 1 addition & 2 deletions spec/unit/openstack_server_show_spec.rb
Original file line number Diff line number Diff line change
@@ -19,13 +19,12 @@
require 'chef/knife/openstack_server_show'
require 'chef/knife/cloud/openstack_service'
require 'support/shared_examples_for_command'
require 'unit/validate_spec'

describe Chef::Knife::Cloud::OpenstackServerShow do
it_behaves_like Chef::Knife::Cloud::Command, Chef::Knife::Cloud::OpenstackServerShow.new

include_context "#validate!", Chef::Knife::Cloud::OpenstackServerShow.new

let (:instance) {Chef::Knife::Cloud::OpenstackServerShow.new}

context "#validate_params!" do

0 comments on commit a574d52

Please sign in to comment.