From 8e374c69148e2a9e5b504a9cc172dd43660563d1 Mon Sep 17 00:00:00 2001 From: Hauke Klement Date: Mon, 16 Feb 2015 17:04:28 +0100 Subject: [PATCH] use #described_class, as suggested by RuboCop --- spec/lib/assessor_spec.rb | 4 +- spec/lib/code_ocean/config_spec.rb | 4 +- spec/lib/docker_client_spec.rb | 50 +++++++++---------- spec/lib/docker_container_pool_spec.rb | 46 ++++++++--------- spec/lib/junit_adapter_spec.rb | 2 +- spec/lib/nonce_store_spec.rb | 20 ++++---- spec/lib/port_pool_spec.rb | 32 ++++++------ spec/lib/py_unit_adapter_spec.rb | 2 +- spec/lib/rspec_adapter_spec.rb | 2 +- .../sql_result_set_comparator_adapter_spec.rb | 2 +- spec/lib/testing_framework_adapter_spec.rb | 4 +- spec/lib/whistleblower_spec.rb | 2 +- spec/mailers/user_mailer_spec.rb | 6 +-- spec/models/code_ocean/file_spec.rb | 2 +- spec/models/consumer_spec.rb | 2 +- spec/models/error_spec.rb | 4 +- spec/models/execution_environment_spec.rb | 2 +- spec/models/exercise_spec.rb | 2 +- spec/models/external_user_spec.rb | 2 +- spec/models/file_type_spec.rb | 2 +- spec/models/hint_spec.rb | 4 +- spec/models/internal_user_spec.rb | 4 +- spec/models/submission_spec.rb | 10 ++-- spec/models/team_spec.rb | 2 +- spec/policies/admin/dashboard_policy_spec.rb | 2 +- spec/policies/application_policy_spec.rb | 2 +- spec/policies/code_ocean/file_policy_spec.rb | 2 +- spec/policies/consumer_policy_spec.rb | 2 +- spec/policies/error_policy_spec.rb | 2 +- .../execution_environment_policy_spec.rb | 2 +- spec/policies/exercise_policy_spec.rb | 2 +- spec/policies/external_user_policy_spec.rb | 2 +- spec/policies/file_type_policy_spec.rb | 2 +- spec/policies/hint_policy_spec.rb | 2 +- spec/policies/internal_user_policy_spec.rb | 2 +- spec/policies/submission_policy_spec.rb | 2 +- spec/policies/team_policy_spec.rb | 2 +- 37 files changed, 119 insertions(+), 119 deletions(-) diff --git a/spec/lib/assessor_spec.rb b/spec/lib/assessor_spec.rb index 2e116a6d..fea9d5c5 100644 --- a/spec/lib/assessor_spec.rb +++ b/spec/lib/assessor_spec.rb @@ -7,7 +7,7 @@ describe Assessor do let(:test_outcome) { {count: count, passed: passed} } context 'with a testing framework adapter' do - let(:assessor) { Assessor.new(execution_environment: FactoryGirl.build(:ruby)) } + let(:assessor) { described_class.new(execution_environment: FactoryGirl.build(:ruby)) } it 'returns the correct score' do expect(assessor.send(:calculate_score, test_outcome)).to eq(passed.to_f / count.to_f) @@ -15,7 +15,7 @@ describe Assessor do end context 'without a testing framework adapter' do - let(:assessor) { Assessor.new(execution_environment: FactoryGirl.build(:execution_environment)) } + let(:assessor) { described_class.new(execution_environment: FactoryGirl.build(:execution_environment)) } it 'raises an error' do expect { assessor.send(:calculate_score, test_outcome) }.to raise_error diff --git a/spec/lib/code_ocean/config_spec.rb b/spec/lib/code_ocean/config_spec.rb index eb05c99b..a8aacfab 100644 --- a/spec/lib/code_ocean/config_spec.rb +++ b/spec/lib/code_ocean/config_spec.rb @@ -7,7 +7,7 @@ describe CodeOcean::Config do context 'with a .yml file' do let(:path) { Rails.root.join('config', "#{filename}.yml") } - let(:read) { CodeOcean::Config.new(filename).read } + let(:read) { described_class.new(filename).read } context 'when the file is present' do before(:each) { File.write(path, {Rails.env.to_s => content}.to_yaml) } @@ -27,7 +27,7 @@ describe CodeOcean::Config do context 'with a .yml.erb file' do let(:path) { Rails.root.join('config', "#{filename}.yml.erb") } - let(:read) { CodeOcean::Config.new(filename).read(erb: true) } + let(:read) { described_class.new(filename).read(erb: true) } context 'when the file is present' do before(:each) { File.write(path, {Rails.env.to_s => content}.to_yaml) } diff --git a/spec/lib/docker_client_spec.rb b/spec/lib/docker_client_spec.rb index 7d1b7093..d688fcd5 100644 --- a/spec/lib/docker_client_spec.rb +++ b/spec/lib/docker_client_spec.rb @@ -3,7 +3,7 @@ require 'seeds_helper' describe DockerClient, docker: true do let(:command) { 'whoami' } - let(:docker_client) { DockerClient.new(execution_environment: FactoryGirl.build(:ruby), user: FactoryGirl.build(:admin)) } + let(:docker_client) { described_class.new(execution_environment: FactoryGirl.build(:ruby), user: FactoryGirl.build(:admin)) } let(:execution_environment) { FactoryGirl.build(:ruby) } let(:image) { double } let(:submission) { FactoryGirl.create(:submission) } @@ -13,27 +13,27 @@ describe DockerClient, docker: true do context 'when a socket error occurs' do it 'raises an error' do expect(Docker).to receive(:version).and_raise(Excon::Errors::SocketError.new(StandardError.new)) - expect { DockerClient.check_availability! }.to raise_error(DockerClient::Error) + expect { described_class.check_availability! }.to raise_error(DockerClient::Error) end end context 'when a timeout occurs' do it 'raises an error' do expect(Docker).to receive(:version).and_raise(Timeout::Error) - expect { DockerClient.check_availability! }.to raise_error(DockerClient::Error) + expect { described_class.check_availability! }.to raise_error(DockerClient::Error) end end end describe '.create_container' do - after(:each) { DockerClient.create_container(execution_environment) } + after(:each) { described_class.create_container(execution_environment) } it 'uses the correct Docker image' do - expect(DockerClient).to receive(:find_image_by_tag).with(execution_environment.docker_image).and_call_original + expect(described_class).to receive(:find_image_by_tag).with(execution_environment.docker_image).and_call_original end it 'creates a unique directory' do - expect(DockerClient).to receive(:generate_local_workspace_path).and_call_original + expect(described_class).to receive(:generate_local_workspace_path).and_call_original expect(FileUtils).to receive(:mkdir).with(kind_of(String)).and_call_original end @@ -46,12 +46,12 @@ describe DockerClient, docker: true do end it 'configures mapped directories' do - expect(DockerClient).to receive(:mapped_directories).and_call_original + expect(described_class).to receive(:mapped_directories).and_call_original expect_any_instance_of(Docker::Container).to receive(:start).with(hash_including('Binds' => kind_of(Array))) end it 'configures mapped ports' do - expect(DockerClient).to receive(:mapped_ports).with(execution_environment).and_call_original + expect(described_class).to receive(:mapped_ports).with(execution_environment).and_call_original expect_any_instance_of(Docker::Container).to receive(:start).with(hash_including('PortBindings' => kind_of(Hash))) end end @@ -89,7 +89,7 @@ describe DockerClient, docker: true do after(:each) { File.delete(file_path) } it 'creates a file' do - expect(DockerClient).to receive(:local_workspace_path).at_least(:once).and_return(workspace_path) + expect(described_class).to receive(:local_workspace_path).at_least(:once).and_return(workspace_path) docker_client.send(:create_workspace_file, container: CONTAINER, file: file) expect(File.exist?(file_path)).to be true expect(File.new(file_path, 'r').read).to eq(file.content) @@ -97,8 +97,8 @@ describe DockerClient, docker: true do end describe '.destroy_container' do - let(:container) { DockerClient.create_container(execution_environment) } - after(:each) { DockerClient.destroy_container(container) } + let(:container) { described_class.create_container(execution_environment) } + after(:each) { described_class.destroy_container(container) } it 'stops the container' do expect(container).to receive(:stop).and_return(container) @@ -114,7 +114,7 @@ describe DockerClient, docker: true do end it 'removes the mapped directory' do - expect(DockerClient).to receive(:local_workspace_path).and_return(workspace_path) + expect(described_class).to receive(:local_workspace_path).and_return(workspace_path) expect(FileUtils).to receive(:rm_rf).with(workspace_path) end @@ -173,12 +173,12 @@ describe DockerClient, docker: true do describe '.generate_local_workspace_path' do it 'includes the correct workspace root' do - expect(DockerClient.generate_local_workspace_path).to start_with(DockerClient::LOCAL_WORKSPACE_ROOT.to_s) + expect(described_class.generate_local_workspace_path).to start_with(DockerClient::LOCAL_WORKSPACE_ROOT.to_s) end it 'includes a UUID' do expect(SecureRandom).to receive(:uuid).and_call_original - DockerClient.generate_local_workspace_path + described_class.generate_local_workspace_path end end @@ -186,22 +186,22 @@ describe DockerClient, docker: true do context 'with complete configuration' do it 'creates the file directory' do expect(FileUtils).to receive(:mkdir_p).with(DockerClient::LOCAL_WORKSPACE_ROOT) - DockerClient.initialize_environment + described_class.initialize_environment end end context 'with incomplete configuration' do - before(:each) { expect(DockerClient).to receive(:config).at_least(:once).and_return({}) } + before(:each) { expect(described_class).to receive(:config).at_least(:once).and_return({}) } it 'raises an error' do - expect { DockerClient.initialize_environment }.to raise_error(DockerClient::Error) + expect { described_class.initialize_environment }.to raise_error(DockerClient::Error) end end end describe '.local_workspace_path' do - let(:container) { DockerClient.create_container(execution_environment) } - let(:local_workspace_path) { DockerClient.local_workspace_path(container) } + let(:container) { described_class.create_container(execution_environment) } + let(:local_workspace_path) { described_class.local_workspace_path(container) } it 'returns a path' do expect(local_workspace_path).to be_a(Pathname) @@ -214,7 +214,7 @@ describe DockerClient, docker: true do describe '.mapped_directories' do it 'returns a unique mapping' do - mapping = DockerClient.mapped_directories(workspace_path).first + mapping = described_class.mapped_directories(workspace_path).first expect(mapping).to start_with(workspace_path) expect(mapping).to end_with(DockerClient::CONTAINER_WORKSPACE_PATH) end @@ -225,26 +225,26 @@ describe DockerClient, docker: true do before(:each) { execution_environment.exposed_ports = '3000' } it 'returns a mapping' do - expect(DockerClient.mapped_ports(execution_environment)).to be_a(Hash) - expect(DockerClient.mapped_ports(execution_environment).length).to eq(1) + expect(described_class.mapped_ports(execution_environment)).to be_a(Hash) + expect(described_class.mapped_ports(execution_environment).length).to eq(1) end it 'retrieves available ports' do expect(PortPool).to receive(:available_port) - DockerClient.mapped_ports(execution_environment) + described_class.mapped_ports(execution_environment) end end context 'without exposed ports' do it 'returns an empty mapping' do - expect(DockerClient.mapped_ports(execution_environment)).to eq({}) + expect(described_class.mapped_ports(execution_environment)).to eq({}) end end end describe '#send_command' do let(:block) { Proc.new {} } - let(:container) { DockerClient.create_container(execution_environment) } + let(:container) { described_class.create_container(execution_environment) } let(:send_command) { docker_client.send(:send_command, command, container, &block) } after(:each) { send_command } diff --git a/spec/lib/docker_container_pool_spec.rb b/spec/lib/docker_container_pool_spec.rb index 792fa14d..4f8286b4 100644 --- a/spec/lib/docker_container_pool_spec.rb +++ b/spec/lib/docker_container_pool_spec.rb @@ -14,20 +14,20 @@ describe DockerContainerPool do end it 'uses thread-safe data structures' do - expect(DockerContainerPool.instance_variable_get(:@containers)).to be_a(ThreadSafe::Hash) - expect(DockerContainerPool.instance_variable_get(:@containers)[@execution_environment.id]).to be_a(ThreadSafe::Array) + expect(described_class.instance_variable_get(:@containers)).to be_a(ThreadSafe::Hash) + expect(described_class.instance_variable_get(:@containers)[@execution_environment.id]).to be_a(ThreadSafe::Array) end describe '.clean_up' do - before(:each) { DockerContainerPool.instance_variable_set(:@refill_task, double) } - after(:each) { DockerContainerPool.clean_up } + before(:each) { described_class.instance_variable_set(:@refill_task, double) } + after(:each) { described_class.clean_up } it 'stops the refill task' do - expect(DockerContainerPool.instance_variable_get(:@refill_task)).to receive(:shutdown) + expect(described_class.instance_variable_get(:@refill_task)).to receive(:shutdown) end it 'destroys all containers' do - DockerContainerPool.instance_variable_get(:@containers).each do |key, value| + described_class.instance_variable_get(:@containers).each do |key, value| value.each do |container| expect(DockerClient).to receive(:destroy_container).with(container) end @@ -38,46 +38,46 @@ describe DockerContainerPool do describe '.get_container' do context 'when active' do before(:each) do - expect(DockerContainerPool).to receive(:config).and_return(active: true) + expect(described_class).to receive(:config).and_return(active: true) end context 'with an available container' do - before(:each) { DockerContainerPool.instance_variable_get(:@containers)[@execution_environment.id].push(container) } + before(:each) { described_class.instance_variable_get(:@containers)[@execution_environment.id].push(container) } it 'takes a container from the pool' do - expect(DockerContainerPool).not_to receive(:create_container).with(@execution_environment) - expect(DockerContainerPool.get_container(@execution_environment)).to eq(container) + expect(described_class).not_to receive(:create_container).with(@execution_environment) + expect(described_class.get_container(@execution_environment)).to eq(container) end end context 'without an available container' do before(:each) do - expect(DockerContainerPool.instance_variable_get(:@containers)[@execution_environment.id]).to be_empty + expect(described_class.instance_variable_get(:@containers)[@execution_environment.id]).to be_empty end it 'creates a new container' do - expect(DockerContainerPool).to receive(:create_container).with(@execution_environment) - DockerContainerPool.get_container(@execution_environment) + expect(described_class).to receive(:create_container).with(@execution_environment) + described_class.get_container(@execution_environment) end end end context 'when inactive' do before(:each) do - expect(DockerContainerPool).to receive(:config).and_return(active: false) + expect(described_class).to receive(:config).and_return(active: false) end it 'creates a new container' do - expect(DockerContainerPool).to receive(:create_container).with(@execution_environment) - DockerContainerPool.get_container(@execution_environment) + expect(described_class).to receive(:create_container).with(@execution_environment) + described_class.get_container(@execution_environment) end end end describe '.quantities' do it 'maps execution environments to quantities of available containers' do - expect(DockerContainerPool.quantities.keys).to eq(ExecutionEnvironment.all.map(&:id)) - expect(DockerContainerPool.quantities.values.uniq).to eq([0]) + expect(described_class.quantities.keys).to eq(ExecutionEnvironment.all.map(&:id)) + expect(described_class.quantities.values.uniq).to eq([0]) end end @@ -86,15 +86,15 @@ describe DockerContainerPool do let(:maximum_refill_count) { 5 } before(:each) do - expect(DockerContainerPool).to receive(:config).and_return(config) + expect(described_class).to receive(:config).and_return(config) expect(config).to receive(:[]).with(:maximum_refill_count).and_return(maximum_refill_count) end - after(:each) { DockerContainerPool.refill } + after(:each) { described_class.refill } it 'regards all execution environments' do ExecutionEnvironment.all.each do |execution_environment| - expect(DockerContainerPool.instance_variable_get(:@containers)).to receive(:[]).with(execution_environment.id).and_call_original + expect(described_class.instance_variable_get(:@containers)).to receive(:[]).with(execution_environment.id).and_call_original end end @@ -103,7 +103,7 @@ describe DockerContainerPool do it 'complies with the maximum batch size' do expect_any_instance_of(Concurrent::Future).to receive(:execute) do |future| - expect(DockerContainerPool).to receive(:create_container).with(@execution_environment).exactly(maximum_refill_count).times + expect(described_class).to receive(:create_container).with(@execution_environment).exactly(maximum_refill_count).times future.instance_variable_get(:@task).call end end @@ -123,7 +123,7 @@ describe DockerContainerPool do end describe '.start_refill_task' do - after(:each) { DockerContainerPool.start_refill_task } + after(:each) { described_class.start_refill_task } it 'creates an asynchronous task' do expect(Concurrent::TimerTask).to receive(:new).and_call_original diff --git a/spec/lib/junit_adapter_spec.rb b/spec/lib/junit_adapter_spec.rb index 2a7ae591..beaf3e16 100644 --- a/spec/lib/junit_adapter_spec.rb +++ b/spec/lib/junit_adapter_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe JunitAdapter do - let(:adapter) { JunitAdapter.new } + let(:adapter) { described_class.new } describe '#parse_output' do context 'with failed tests' do diff --git a/spec/lib/nonce_store_spec.rb b/spec/lib/nonce_store_spec.rb index 6641b51c..8b32726e 100644 --- a/spec/lib/nonce_store_spec.rb +++ b/spec/lib/nonce_store_spec.rb @@ -6,36 +6,36 @@ describe NonceStore do describe '.add' do it 'stores a nonce in the cache' do expect(Rails.cache).to receive(:write) - NonceStore.add(nonce) + described_class.add(nonce) end end describe '.delete' do it 'deletes a nonce from the cache' do expect(Rails.cache).to receive(:write) - NonceStore.add(nonce) - NonceStore.delete(nonce) - expect(NonceStore.has?(nonce)).to be false + described_class.add(nonce) + described_class.delete(nonce) + expect(described_class.has?(nonce)).to be false end end describe '.has?' do it 'returns true for present nonces' do - NonceStore.add(nonce) - expect(NonceStore.has?(nonce)).to be true + described_class.add(nonce) + expect(described_class.has?(nonce)).to be true end it 'returns false for expired nonces' do Lti.send(:remove_const, 'MAXIMUM_SESSION_AGE') Lti::MAXIMUM_SESSION_AGE = 1 - NonceStore.add(nonce) - expect(NonceStore.has?(nonce)).to be true + described_class.add(nonce) + expect(described_class.has?(nonce)).to be true sleep(Lti::MAXIMUM_SESSION_AGE) - expect(NonceStore.has?(nonce)).to be false + expect(described_class.has?(nonce)).to be false end it 'returns false for absent nonces' do - expect(NonceStore.has?(nonce)).to be false + expect(described_class.has?(nonce)).to be false end end end diff --git a/spec/lib/port_pool_spec.rb b/spec/lib/port_pool_spec.rb index 5fbcd563..95f75686 100644 --- a/spec/lib/port_pool_spec.rb +++ b/spec/lib/port_pool_spec.rb @@ -3,27 +3,27 @@ require 'rails_helper' describe PortPool do describe '.available_port' do it 'is synchronized' do - expect(PortPool.instance_variable_get(:@mutex)).to receive(:synchronize) - PortPool.available_port + expect(described_class.instance_variable_get(:@mutex)).to receive(:synchronize) + described_class.available_port end context 'when a port is available' do it 'returns the port' do - expect(PortPool.available_port).to be_a(Numeric) + expect(described_class.available_port).to be_a(Numeric) end it 'removes the port from the list of available ports' do - port = PortPool.available_port - expect(PortPool.instance_variable_get(:@available_ports)).not_to include(port) + port = described_class.available_port + expect(described_class.instance_variable_get(:@available_ports)).not_to include(port) end end context 'when no port is available' do it 'returns the port' do - available_ports = PortPool.instance_variable_get(:@available_ports) - PortPool.instance_variable_set(:@available_ports, []) - expect(PortPool.available_port).to be_nil - PortPool.instance_variable_set(:@available_ports, available_ports) + available_ports = described_class.instance_variable_get(:@available_ports) + described_class.instance_variable_set(:@available_ports, []) + expect(described_class.available_port).to be_nil + described_class.instance_variable_set(:@available_ports, available_ports) end end end @@ -31,24 +31,24 @@ describe PortPool do describe '.release' do context 'when the port has been obtained earlier' do it 'adds the port to the list of available ports' do - port = PortPool.available_port - expect(PortPool.instance_variable_get(:@available_ports)).not_to include(port) - PortPool.release(port) - expect(PortPool.instance_variable_get(:@available_ports)).to include(port) + port = described_class.available_port + expect(described_class.instance_variable_get(:@available_ports)).not_to include(port) + described_class.release(port) + expect(described_class.instance_variable_get(:@available_ports)).to include(port) end end context 'when the port has not been obtained earlier' do it 'does not add the port to the list of available ports' do - port = PortPool.instance_variable_get(:@available_ports).sample - expect { PortPool.release(port) }.not_to change { PortPool.instance_variable_get(:@available_ports).length } + port = described_class.instance_variable_get(:@available_ports).sample + expect { described_class.release(port) }.not_to change { described_class.instance_variable_get(:@available_ports).length } end end context 'when the port is not included in the port range' do it 'does not add the port to the list of available ports' do port = nil - expect { PortPool.release(port) }.not_to change { PortPool.instance_variable_get(:@available_ports).length } + expect { described_class.release(port) }.not_to change { described_class.instance_variable_get(:@available_ports).length } end end end diff --git a/spec/lib/py_unit_adapter_spec.rb b/spec/lib/py_unit_adapter_spec.rb index 96a325ea..5e8ee89b 100644 --- a/spec/lib/py_unit_adapter_spec.rb +++ b/spec/lib/py_unit_adapter_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe PyUnitAdapter do - let(:adapter) { PyUnitAdapter.new } + let(:adapter) { described_class.new } let(:count) { 42 } let(:failed) { 25 } let(:stderr) { "Ran #{count} tests in 0.1s\n\nFAILED (failures=#{failed})" } diff --git a/spec/lib/rspec_adapter_spec.rb b/spec/lib/rspec_adapter_spec.rb index 273b3bb0..0563cf7a 100644 --- a/spec/lib/rspec_adapter_spec.rb +++ b/spec/lib/rspec_adapter_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe RspecAdapter do - let(:adapter) { RspecAdapter.new } + let(:adapter) { described_class.new } let(:count) { 42 } let(:failed) { 25 } let(:stdout) { "Finished in 0.1 seconds (files took 0.1 seconds to load)\n#{count} examples, #{failed} failures" } diff --git a/spec/lib/sql_result_set_comparator_adapter_spec.rb b/spec/lib/sql_result_set_comparator_adapter_spec.rb index 5674d094..dafcdcc6 100644 --- a/spec/lib/sql_result_set_comparator_adapter_spec.rb +++ b/spec/lib/sql_result_set_comparator_adapter_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe SqlResultSetComparatorAdapter do - let(:adapter) { SqlResultSetComparatorAdapter.new } + let(:adapter) { described_class.new } describe '#parse_output' do context 'with missing tuples' do diff --git a/spec/lib/testing_framework_adapter_spec.rb b/spec/lib/testing_framework_adapter_spec.rb index 92d5fb6e..f09d0778 100644 --- a/spec/lib/testing_framework_adapter_spec.rb +++ b/spec/lib/testing_framework_adapter_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe TestingFrameworkAdapter do - let(:adapter) { TestingFrameworkAdapter.new } + let(:adapter) { described_class.new } let(:count) { 42 } let(:failed) { 25 } let(:passed) { 17 } @@ -28,7 +28,7 @@ describe TestingFrameworkAdapter do describe '.framework_name' do it 'defaults to the class name' do - expect(adapter.class.framework_name).to eq(TestingFrameworkAdapter.name) + expect(adapter.class.framework_name).to eq(described_class.name) end end diff --git a/spec/lib/whistleblower_spec.rb b/spec/lib/whistleblower_spec.rb index 79613fa0..a7a7c9c6 100644 --- a/spec/lib/whistleblower_spec.rb +++ b/spec/lib/whistleblower_spec.rb @@ -3,7 +3,7 @@ require 'rails_helper' describe Whistleblower do let(:hint) { FactoryGirl.create(:ruby_no_method_error) } let(:stderr) { "undefined method `foo' for main:Object (NoMethodError)" } - let(:whistleblower) { Whistleblower.new(execution_environment: hint.execution_environment) } + let(:whistleblower) { described_class.new(execution_environment: hint.execution_environment) } describe '#find_hint' do let(:find_hint) { whistleblower.send(:find_hint, stderr) } diff --git a/spec/mailers/user_mailer_spec.rb b/spec/mailers/user_mailer_spec.rb index 1a38c3ca..b40b0728 100644 --- a/spec/mailers/user_mailer_spec.rb +++ b/spec/mailers/user_mailer_spec.rb @@ -4,7 +4,7 @@ describe UserMailer do let(:user) { InternalUser.create(FactoryGirl.attributes_for(:teacher)) } describe '#activation_needed_email' do - let(:mail) { UserMailer.activation_needed_email(user) } + let(:mail) { described_class.activation_needed_email(user) } before(:each) do user.send(:setup_activation) @@ -30,12 +30,12 @@ describe UserMailer do describe '#activation_success_email' do it 'does not raise an error' do - expect { UserMailer.activation_success_email(user) }.not_to raise_error + expect { described_class.activation_success_email(user) }.not_to raise_error end end describe '#reset_password_email' do - let(:mail) { UserMailer.reset_password_email(user) } + let(:mail) { described_class.reset_password_email(user) } it 'sets the correct sender' do expect(mail.from).to include(CodeOcean::Application.config.action_mailer[:default_options][:from]) diff --git a/spec/models/code_ocean/file_spec.rb b/spec/models/code_ocean/file_spec.rb index d13ffabb..104832bd 100644 --- a/spec/models/code_ocean/file_spec.rb +++ b/spec/models/code_ocean/file_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe CodeOcean::File do - let(:file) { CodeOcean::File.create.tap { |file| file.update(content: nil, hidden: nil, read_only: nil) } } + let(:file) { described_class.create.tap { |file| file.update(content: nil, hidden: nil, read_only: nil) } } it 'validates the presence of a file type' do expect(file.errors[:file_type_id]).to be_present diff --git a/spec/models/consumer_spec.rb b/spec/models/consumer_spec.rb index 7f7a53cd..ed5e0fbe 100644 --- a/spec/models/consumer_spec.rb +++ b/spec/models/consumer_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe Consumer do - let(:consumer) { Consumer.create } + let(:consumer) { described_class.create } it 'validates the presence of a name' do expect(consumer.errors[:name]).to be_present diff --git a/spec/models/error_spec.rb b/spec/models/error_spec.rb index 040a27e4..7f9f405a 100644 --- a/spec/models/error_spec.rb +++ b/spec/models/error_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe Error do - let(:error) { Error.create } + let(:error) { described_class.create } it 'validates the presence of an execution environment' do expect(error.errors[:execution_environment_id]).to be_present @@ -13,7 +13,7 @@ describe Error do describe '.nested_resource?' do it 'is true' do - expect(Error.nested_resource?).to be true + expect(described_class.nested_resource?).to be true end end end diff --git a/spec/models/execution_environment_spec.rb b/spec/models/execution_environment_spec.rb index f347f2b0..bbb8df81 100644 --- a/spec/models/execution_environment_spec.rb +++ b/spec/models/execution_environment_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe ExecutionEnvironment do - let(:execution_environment) { ExecutionEnvironment.create } + let(:execution_environment) { described_class.create } it 'validates that the Docker image works', docker: true do expect(execution_environment).to receive(:validate_docker_image?).and_return(true) diff --git a/spec/models/exercise_spec.rb b/spec/models/exercise_spec.rb index 3deb0fec..aa63dc7e 100644 --- a/spec/models/exercise_spec.rb +++ b/spec/models/exercise_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe Exercise do - let(:exercise) { Exercise.create.tap { |exercise| exercise.update(public: nil, token: nil) } } + let(:exercise) { described_class.create.tap { |exercise| exercise.update(public: nil, token: nil) } } it 'validates the presence of a description' do expect(exercise.errors[:description]).to be_present diff --git a/spec/models/external_user_spec.rb b/spec/models/external_user_spec.rb index e5be1e93..29243246 100644 --- a/spec/models/external_user_spec.rb +++ b/spec/models/external_user_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe ExternalUser do - let(:user) { ExternalUser.create } + let(:user) { described_class.create } it 'validates the presence of a consumer' do expect(user.errors[:consumer_id]).to be_present diff --git a/spec/models/file_type_spec.rb b/spec/models/file_type_spec.rb index a62ca909..89de68b5 100644 --- a/spec/models/file_type_spec.rb +++ b/spec/models/file_type_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe FileType do - let(:file_type) { FileType.create.tap { |file_type| file_type.update(binary: nil, executable: nil, renderable: nil) } } + let(:file_type) { described_class.create.tap { |file_type| file_type.update(binary: nil, executable: nil, renderable: nil) } } it 'validates the presence of the binary flag' do expect(file_type.errors[:binary]).to be_present diff --git a/spec/models/hint_spec.rb b/spec/models/hint_spec.rb index 377d6dac..87e04b51 100644 --- a/spec/models/hint_spec.rb +++ b/spec/models/hint_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe Hint do - let(:hint) { Hint.create } + let(:hint) { described_class.create } it 'validates the presence of an execution environment' do expect(hint.errors[:execution_environment_id]).to be_present @@ -25,7 +25,7 @@ describe Hint do describe '.nested_resource?' do it 'is true' do - expect(Hint.nested_resource?).to be true + expect(described_class.nested_resource?).to be true end end diff --git a/spec/models/internal_user_spec.rb b/spec/models/internal_user_spec.rb index 9e8c5e6b..f13e6236 100644 --- a/spec/models/internal_user_spec.rb +++ b/spec/models/internal_user_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' describe InternalUser do let(:password) { SecureRandom.hex } - let(:user) { InternalUser.create } + let(:user) { described_class.create } it 'validates the presence of an email address' do expect(user.errors[:email]).to be_present @@ -27,7 +27,7 @@ describe InternalUser do end context 'when not activated' do - let(:user) { InternalUser.create(FactoryGirl.attributes_for(:teacher, activation_state: 'pending', password: nil)) } + let(:user) { described_class.create(FactoryGirl.attributes_for(:teacher, activation_state: 'pending', password: nil)) } it 'validates the confirmation of the password' do user.update(password: password, password_confirmation: '') diff --git a/spec/models/submission_spec.rb b/spec/models/submission_spec.rb index 45d093b1..a5c15960 100644 --- a/spec/models/submission_spec.rb +++ b/spec/models/submission_spec.rb @@ -6,16 +6,16 @@ describe Submission do end it 'validates the presence of a cause' do - expect(Submission.create.errors[:cause]).to be_present + expect(described_class.create.errors[:cause]).to be_present end it 'validates the presence of an exercise' do - expect(Submission.create.errors[:exercise_id]).to be_present + expect(described_class.create.errors[:exercise_id]).to be_present end it 'validates the presence of a user' do - expect(Submission.create.errors[:user_id]).to be_present - expect(Submission.create.errors[:user_type]).to be_present + expect(described_class.create.errors[:user_id]).to be_present + expect(described_class.create.errors[:user_type]).to be_present end %w(download render run test).each do |action| @@ -35,7 +35,7 @@ describe Submission do describe '#to_s' do it "equals the class' model name" do - expect(@submission.to_s).to eq(Submission.model_name.human) + expect(@submission.to_s).to eq(described_class.model_name.human) end end end diff --git a/spec/models/team_spec.rb b/spec/models/team_spec.rb index 40725c15..777efd32 100644 --- a/spec/models/team_spec.rb +++ b/spec/models/team_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe Team do - let(:team) { Team.create } + let(:team) { described_class.create } it 'validates the presence of a name' do expect(team.errors[:name]).to be_present diff --git a/spec/policies/admin/dashboard_policy_spec.rb b/spec/policies/admin/dashboard_policy_spec.rb index 252b2395..0592843a 100644 --- a/spec/policies/admin/dashboard_policy_spec.rb +++ b/spec/policies/admin/dashboard_policy_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe Admin::DashboardPolicy do - subject { Admin::DashboardPolicy } + subject { described_class } permissions :show? do it 'grants access to admins' do diff --git a/spec/policies/application_policy_spec.rb b/spec/policies/application_policy_spec.rb index 7eca881d..6ab7864a 100644 --- a/spec/policies/application_policy_spec.rb +++ b/spec/policies/application_policy_spec.rb @@ -4,7 +4,7 @@ describe ApplicationPolicy do describe '#initialize' do context 'without a user' do it 'raises an error' do - expect { ApplicationPolicy.new(nil, nil) }.to raise_error(Pundit::NotAuthorizedError) + expect { described_class.new(nil, nil) }.to raise_error(Pundit::NotAuthorizedError) end end end diff --git a/spec/policies/code_ocean/file_policy_spec.rb b/spec/policies/code_ocean/file_policy_spec.rb index 80e5ad53..5f7be142 100644 --- a/spec/policies/code_ocean/file_policy_spec.rb +++ b/spec/policies/code_ocean/file_policy_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe CodeOcean::FilePolicy do - subject { CodeOcean::FilePolicy } + subject { described_class } permissions :create? do context 'as part of an exercise' do diff --git a/spec/policies/consumer_policy_spec.rb b/spec/policies/consumer_policy_spec.rb index 23f02ea7..01b74dd3 100644 --- a/spec/policies/consumer_policy_spec.rb +++ b/spec/policies/consumer_policy_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe ConsumerPolicy do - subject { ConsumerPolicy } + subject { described_class } [:create?, :destroy?, :edit?, :index?, :new?, :show?, :update?].each do |action| permissions(action) do diff --git a/spec/policies/error_policy_spec.rb b/spec/policies/error_policy_spec.rb index bde0e490..1c4964b2 100644 --- a/spec/policies/error_policy_spec.rb +++ b/spec/policies/error_policy_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe ErrorPolicy do - subject { ErrorPolicy } + subject { described_class } let(:error) { FactoryGirl.build(:error) } diff --git a/spec/policies/execution_environment_policy_spec.rb b/spec/policies/execution_environment_policy_spec.rb index 6ae7b2b0..799881b5 100644 --- a/spec/policies/execution_environment_policy_spec.rb +++ b/spec/policies/execution_environment_policy_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe ExecutionEnvironmentPolicy do - subject { ExecutionEnvironmentPolicy } + subject { described_class } let(:execution_environment) { FactoryGirl.build(:ruby) } diff --git a/spec/policies/exercise_policy_spec.rb b/spec/policies/exercise_policy_spec.rb index 624c93f8..9e3d268c 100644 --- a/spec/policies/exercise_policy_spec.rb +++ b/spec/policies/exercise_policy_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe ExercisePolicy do - subject { ExercisePolicy } + subject { described_class } before(:all) do @exercise = FactoryGirl.build(:dummy, team: FactoryGirl.create(:team)) diff --git a/spec/policies/external_user_policy_spec.rb b/spec/policies/external_user_policy_spec.rb index 248b93bc..be506c7f 100644 --- a/spec/policies/external_user_policy_spec.rb +++ b/spec/policies/external_user_policy_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe ExternalUserPolicy do - subject { ExternalUserPolicy } + subject { described_class } [:create?, :destroy?, :edit?, :index?, :new?, :show?, :update?].each do |action| permissions(action) do diff --git a/spec/policies/file_type_policy_spec.rb b/spec/policies/file_type_policy_spec.rb index 5206f67f..042e4393 100644 --- a/spec/policies/file_type_policy_spec.rb +++ b/spec/policies/file_type_policy_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe FileTypePolicy do - subject { FileTypePolicy } + subject { described_class } let(:file_type) { FactoryGirl.build(:dot_rb) } diff --git a/spec/policies/hint_policy_spec.rb b/spec/policies/hint_policy_spec.rb index a6a8c6d7..ccde798f 100644 --- a/spec/policies/hint_policy_spec.rb +++ b/spec/policies/hint_policy_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe HintPolicy do - subject { HintPolicy } + subject { described_class } let(:hint) { FactoryGirl.build(:ruby_no_method_error) } diff --git a/spec/policies/internal_user_policy_spec.rb b/spec/policies/internal_user_policy_spec.rb index d7cb12ec..3ad6e7d9 100644 --- a/spec/policies/internal_user_policy_spec.rb +++ b/spec/policies/internal_user_policy_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe InternalUserPolicy do - subject { InternalUserPolicy } + subject { described_class } [:create?, :edit?, :index?, :new?, :show?, :update?].each do |action| permissions(action) do diff --git a/spec/policies/submission_policy_spec.rb b/spec/policies/submission_policy_spec.rb index d04059a7..f844b984 100644 --- a/spec/policies/submission_policy_spec.rb +++ b/spec/policies/submission_policy_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe SubmissionPolicy do - subject { SubmissionPolicy } + subject { described_class } permissions :create? do it 'grants access to anyone' do diff --git a/spec/policies/team_policy_spec.rb b/spec/policies/team_policy_spec.rb index f3802a2c..aa3ba1d8 100644 --- a/spec/policies/team_policy_spec.rb +++ b/spec/policies/team_policy_spec.rb @@ -1,7 +1,7 @@ require 'rails_helper' describe TeamPolicy do - subject { TeamPolicy } + subject { described_class } let(:team) { FactoryGirl.build(:team) }