From c7111ad7ad250251f29c3bcbaf274c651b70bb08 Mon Sep 17 00:00:00 2001 From: Mark Moser Date: Tue, 16 Aug 2016 15:20:16 -0500 Subject: [PATCH] added simplecov for test coverge report --- Guardfile | 2 +- config/environments/development.rb | 4 ++++ config/environments/test.rb | 4 ++++ test/test_helper.rb | 7 ++++++ test/workers/candidate_quiz_question_test.rb | 25 +++++++++++--------- 5 files changed, 30 insertions(+), 12 deletions(-) diff --git a/Guardfile b/Guardfile index 5f22305..e686215 100644 --- a/Guardfile +++ b/Guardfile @@ -15,7 +15,7 @@ # # and, you'll have to watch "config/Guardfile" instead of "Guardfile" -guard :minitest, spring: "bin/rails test", all_after_pass: true, all_on_start: false do +guard :minitest, spring: true, all_after_pass: true, all_on_start: false do watch(%r{^test/test_helper\.rb$}) { 'test' } watch(%r{^test/(.*)\/?(.*)_test\.rb$}) diff --git a/config/environments/development.rb b/config/environments/development.rb index 6f71970..88c86ee 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -51,4 +51,8 @@ Rails.application.configure do # Use an evented file watcher to asynchronously detect changes in source code, # routes, locales, etc. This feature depends on the listen gem. config.file_watcher = ActiveSupport::EventedFileUpdateChecker + + # Disable Rails's static asset server (Apache or nginx will already do this) + config.public_file_server.enabled = false + config.eager_load = false end diff --git a/config/environments/test.rb b/config/environments/test.rb index 30587ef..bb560d5 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -39,4 +39,8 @@ Rails.application.configure do # Raises error for missing translations # config.action_view.raise_on_missing_translations = true + + # Disable Rails's static asset server (Apache or nginx will already do this) + config.public_file_server.enabled = false + config.eager_load = false end diff --git a/test/test_helper.rb b/test/test_helper.rb index b3eba45..5c9b571 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,5 +1,12 @@ ENV['RAILS_ENV'] ||= 'test' +# https://github.com/colszowka/simplecov +require 'simplecov' +SimpleCov.start 'rails' do + add_group 'Models', ['app/models', 'app/validators'] + add_group 'Services & Workers', ['app/workers', 'app/services'] +end + require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' require "minitest/autorun" diff --git a/test/workers/candidate_quiz_question_test.rb b/test/workers/candidate_quiz_question_test.rb index 7d09060..dde32f9 100644 --- a/test/workers/candidate_quiz_question_test.rb +++ b/test/workers/candidate_quiz_question_test.rb @@ -2,16 +2,12 @@ require 'test_helper' class CandidateQuizQuestionTest < ActiveSupport::TestCase def setup - @row = { - "candidate_id" => "12345", - "quiz_id" => 9876, - "question_id" => 5, - "answer_id" => 6, - "question" => 'what now?', - "input_type" => 'text', - "input_options" => %w(one two three).to_yaml, - "answer" => { test: 1, foo: 'bar', cheer: 'huzzah!' }.to_yaml - } + @row = { "candidate_id" => "12345", "quiz_id" => 9876, "question_id" => 5, "answer_id" => 6, + "input_type" => 'text', "question" => 'what now?', + "input_options" => %w(one two three).to_yaml, + "answer" => { test: 1, foo: 'bar', cheer: 'huzzah!' }.to_yaml, + "saved" => false, "submitted" => true, + "updated_at" => DateTime.parse('20160816') } end test "propper dot attributes work" do @@ -23,8 +19,15 @@ class CandidateQuizQuestionTest < ActiveSupport::TestCase assert_equal 6, question.answer_id assert_equal 'what now?', question.question assert_equal 'text', question.input_type + assert_equal false, question.saved + assert_equal true, question.submitted + assert_equal DateTime.parse('20160816'), question.updated_at + end + + test 'should handle array of input options' do + question = CandidateQuizQuestion.new @row + assert_kind_of Array, question.input_options - assert_kind_of Hash, question.answer end test "should handle string answer" do