diff --git a/Gemfile b/Gemfile index 2d7df98..462e56f 100644 --- a/Gemfile +++ b/Gemfile @@ -5,7 +5,7 @@ gem 'rspec' gem 'rspec-core' gem 'rspec-rails' -#for test coverage +# for test coverage # gem 'simplecov', '~> 0.9.1', :require => false, :group => :test # static code checking tools @@ -14,3 +14,4 @@ gem 'rubocop-performance' gem 'rubocop-rails' gem 'rubocop-rake' gem 'rubocop-rspec' +gem 'rubocop-thread_safety' diff --git a/init.rb b/init.rb index 6f2ae8b..ec34dd8 100644 --- a/init.rb +++ b/init.rb @@ -2,7 +2,7 @@ name 'Redmine Base Rspec plugin' author 'Jean-Baptiste BARTH (orig)' description 'RSpec and RuboCop support' - version '3.0.2' + version '3.0.3' url 'https://github.com/tools-aoeur/redmine_base_rspec' author_url 'https://github.com/tools-aoeur' end diff --git a/lib/tasks/redmine.rake b/lib/tasks/redmine.rake index 203c501..f7dcd23 100644 --- a/lib/tasks/redmine.rake +++ b/lib/tasks/redmine.rake @@ -8,7 +8,7 @@ namespace :redmine do namespace :plugins do desc 'Runs the plugins tests.' task test: :environment do - if !ENV['NAME'] || File.exist?(Rails.root.join("plugins/#{ENV['NAME']}/spec")) + if !ENV['NAME'] || Rails.root.join("plugins/#{ENV.fetch('NAME', nil)}/spec").exist? Rake::Task['redmine:plugins:spec'].invoke end Rake::Task['redmine:plugins:test:units'].invoke diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index f4a2c2d..2da9873 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -9,7 +9,7 @@ # Add additional requires below this line. Rails is not loaded until this point! -require File.expand_path("#{::Rails.root}/test/object_helpers", __FILE__) +require Rails.root.join('test/object_helpers').expand_path(__FILE__) include ObjectHelpers # Requires supporting ruby files with custom matchers and macros, etc, in @@ -29,7 +29,7 @@ RSpec.configure do |config| # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures - config.fixture_path = "#{::Rails.root}/test/fixtures" + config.fixture_path = Rails.root.join('test/fixtures') # If you're not using ActiveRecord, or you'd prefer not to run each of your # examples within a transaction, remove the following line or assign false diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 1a08b54..fb58973 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -18,10 +18,10 @@ # load rails/redmine require_relative '../../../config/environment' -require File.expand_path("#{::Rails.root}/test/object_helpers", __FILE__) +require Rails.root.join('test/object_helpers').expand_path(__FILE__) include ObjectHelpers -#test gems +# test gems require 'rspec/rails' # require 'rspec/autorun' require 'rspec/mocks' @@ -38,32 +38,32 @@ def document_root_element config.mock_with :rspec config.filter_run focus: true config.run_all_when_everything_filtered = true - config.fixture_path = "#{::Rails.root}/test/fixtures" + config.fixture_path = Rails.root.join('test/fixtures') config.use_transactional_fixtures = true config.infer_spec_type_from_file_location! - config.include AssertSelectRoot, :type => :request + config.include AssertSelectRoot, type: :request config.before(:each, type: :system) do options = {} options[:capabilities] = Selenium::WebDriver::Remote::Capabilities.chrome( 'goog:chromeOptions' => { - 'args' => ["headless", "no-sandbox", "disable-gpu"] + 'args' => %w[headless no-sandbox disable-gpu] } ) driven_by( :selenium, using: :chrome, screen_size: [1024, 900], - options: options + options: options ) end end def with_settings(options, &_block) - saved_settings = options.keys.each_with_object({}) do |k, h| - h[k] = case Setting[k] - when Symbol, false, true, nil - Setting[k] - else - Setting[k].dup - end + saved_settings = options.keys.index_with do |k| + case Setting[k] + when Symbol, false, true, nil + Setting[k] + else + Setting[k].dup + end end options.each { |k, v| Setting[k] = v } yield @@ -73,21 +73,19 @@ def with_settings(options, &_block) def log_user(login, password) visit '/my/page' - expect(current_path).to eq '/login' + expect(page).to have_current_path '/login', ignore_query: true - if Redmine::Plugin.installed?(:redmine_scn) - click_on("ou s'authentifier par login / mot de passe") - end + click_on("ou s'authentifier par login / mot de passe") if Redmine::Plugin.installed?(:redmine_scn) within('#login-form form') do fill_in 'username', with: login fill_in 'password', with: password find('input[name=login]').click end - expect(current_path).to eq '/my/page' + expect(page).to have_current_path '/my/page', ignore_query: true end -def assert_mail_body_match(expected, mail, message=nil) +def assert_mail_body_match(expected, mail, message = nil) if expected.is_a?(String) expect(mail_body(mail)).to include(expected) else @@ -95,9 +93,9 @@ def assert_mail_body_match(expected, mail, message=nil) end end -def assert_mail_body_no_match(expected, mail, message=nil) +def assert_mail_body_no_match(expected, mail, message = nil) if expected.is_a?(String) - expect(mail_body(mail)).to_not include expected + expect(mail_body(mail)).not_to include expected else assert_no_match expected, mail_body(mail), message end @@ -108,5 +106,5 @@ def mail_body(mail) end def uploaded_test_file(name, mime) - fixture_file_upload("#{::Rails.root}/test/fixtures/files/#{name}", mime, true) + fixture_file_upload(Rails.root.join("test/fixtures/files/#{name}"), mime, true) end