Skip to content

Commit

Permalink
use rspec stub_const
Browse files Browse the repository at this point in the history
  • Loading branch information
durandom committed Apr 11, 2017
1 parent 1602e29 commit 833f76d
Showing 1 changed file with 31 additions and 34 deletions.
65 changes: 31 additions & 34 deletions spec/models/dialog_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,52 +9,49 @@
end

it "delegates to the dialog import service with a file in the default directory" do
described_class.with_constants(:DIALOG_DIR_CORE => test_file_path) do
expect(dialog_import_service).to receive(:import_all_service_dialogs_from_yaml_file).with(
Rails.root.join(test_file_path, "seed_test.yaml").to_path
)
expect(dialog_import_service).to receive(:import_all_service_dialogs_from_yaml_file).with(
Rails.root.join(test_file_path, "seed_test.yml").to_path
)
described_class.seed
end
stub_const('Dialog::DIALOG_DIR_CORE', test_file_path)
expect(dialog_import_service).to receive(:import_all_service_dialogs_from_yaml_file).with(
Rails.root.join(test_file_path, "seed_test.yaml").to_path
)
expect(dialog_import_service).to receive(:import_all_service_dialogs_from_yaml_file).with(
Rails.root.join(test_file_path, "seed_test.yml").to_path
)
described_class.seed
end

it "delegates to the dialog import service with a file in a sub directory" do
described_class.with_constants(:DIALOG_DIR_CORE => test_file_path) do
expect(dialog_import_service).to receive(:import_all_service_dialogs_from_yaml_file).with(
Rails.root.join(test_file_path, "service_dialogs/service_seed_test.yaml").to_path
)
expect(dialog_import_service).to receive(:import_all_service_dialogs_from_yaml_file).with(
Rails.root.join(test_file_path, "service_dialogs/service_seed_test.yml").to_path
)
described_class.seed
end
stub_const('Dialog::DIALOG_DIR_CORE', test_file_path)
expect(dialog_import_service).to receive(:import_all_service_dialogs_from_yaml_file).with(
Rails.root.join(test_file_path, "service_dialogs", "service_seed_test.yaml").to_path
)
expect(dialog_import_service).to receive(:import_all_service_dialogs_from_yaml_file).with(
Rails.root.join(test_file_path, "service_dialogs", "service_seed_test.yml").to_path
)
described_class.seed
end

it "delegates to the dialog import service with a symlinked file" do
described_class.with_constants(:DIALOG_DIR_CORE => test_file_path) do
expect(dialog_import_service).to receive(:import_all_service_dialogs_from_yaml_file).with(
Rails.root.join(test_file_path, "service_dialog_symlink/service_seed_test.yaml").to_path
)
expect(dialog_import_service).to receive(:import_all_service_dialogs_from_yaml_file).with(
Rails.root.join(test_file_path, "service_dialog_symlink/service_seed_test.yml").to_path
)
described_class.seed
end
stub_const('Dialog::DIALOG_DIR_CORE', test_file_path)
expect(dialog_import_service).to receive(:import_all_service_dialogs_from_yaml_file).with(
Rails.root.join(test_file_path, "service_dialog_symlink", "service_seed_test.yaml").to_path
)
expect(dialog_import_service).to receive(:import_all_service_dialogs_from_yaml_file).with(
Rails.root.join(test_file_path, "service_dialog_symlink", "service_seed_test.yml").to_path
)
described_class.seed
end

it "seed files from plugins" do
mock_engine = double(:root => Rails.root)
expect(Vmdb::Plugins.instance).to receive(:registered_provider_plugins).and_return([mock_engine])

described_class.with_constants(:DIALOG_DIR_PLUGIN => test_file_path, :DIALOG_DIR_CORE => 'non-existent-dir') do
expect(dialog_import_service).to receive(:import_all_service_dialogs_from_yaml_file).with(
Rails.root.join(test_file_path, "seed_test.yaml").to_path
)
expect(mock_engine).to receive(:root)
described_class.seed
end
stub_const('Dialog::DIALOG_DIR_PLUGIN', test_file_path)
stub_const('Dialog::DIALOG_DIR_CORE', 'non-existent-dir')
expect(dialog_import_service).to receive(:import_all_service_dialogs_from_yaml_file).with(
Rails.root.join(test_file_path, "seed_test.yaml").to_path
)
expect(mock_engine).to receive(:root)
described_class.seed
end
end

Expand Down

0 comments on commit 833f76d

Please sign in to comment.