Skip to content

Commit

Permalink
Add rubocop support
Browse files Browse the repository at this point in the history
  • Loading branch information
mattzollinhofer committed Apr 3, 2016
1 parent 1a532a2 commit d9245a8
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 72 deletions.
12 changes: 12 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
inherit_from: .ruby-style.yml
AllCops:
Include:
- '**/Rakefile'
- '**/config.ru'
Exclude:
- 'db/**/*'
- 'bin/**/*'
- 'config/**/*'
- 'script/**/*'
Rails:
Enabled: true
4 changes: 1 addition & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,11 @@ group :development, :test do
gem 'byebug'
gem 'rspec-rails', '~> 3.0'
gem 'factory_girl_rails'
end

group :development, :test do
gem 'shoulda-matchers', '~> 3.1'
end

group :development do
gem 'rubocop', require: false
gem 'spring-commands-rspec'
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
Expand Down
14 changes: 14 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ GEM
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
arel (6.0.3)
ast (2.2.0)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
builder (3.2.2)
Expand Down Expand Up @@ -77,6 +78,9 @@ GEM
minitest (5.8.4)
nokogiri (1.6.7.2)
mini_portile2 (~> 2.0.0.rc2)
parser (2.3.0.7)
ast (~> 2.2)
powerpack (0.1.1)
rack (1.6.4)
rack-test (0.6.3)
rack (>= 1.0)
Expand Down Expand Up @@ -104,6 +108,7 @@ GEM
activesupport (= 4.2.6)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rainbow (2.1.0)
rake (11.1.2)
rspec-core (3.4.4)
rspec-support (~> 3.4.0)
Expand All @@ -122,6 +127,13 @@ GEM
rspec-mocks (~> 3.4.0)
rspec-support (~> 3.4.0)
rspec-support (3.4.1)
rubocop (0.39.0)
parser (>= 2.3.0.7, < 3.0)
powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.7.5)
sass (3.4.22)
sass-rails (5.0.4)
railties (>= 4.0.0, < 5.0)
Expand Down Expand Up @@ -151,6 +163,7 @@ GEM
thread_safe (~> 0.1)
uglifier (3.0.0)
execjs (>= 0.3.0, < 3)
unicode-display_width (1.0.3)
web-console (2.3.0)
activemodel (>= 4.0)
binding_of_caller (>= 0.7.2)
Expand All @@ -167,6 +180,7 @@ DEPENDENCIES
jquery-rails
rails (= 4.2.6)
rspec-rails (~> 3.0)
rubocop
sass-rails (~> 5.0)
shoulda-matchers (~> 3.1)
spring
Expand Down
8 changes: 6 additions & 2 deletions app/models/assignment.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
class Assignment < ActiveRecord::Base
validates :time_zone_id, inclusion: { in: ActiveSupport::TimeZone.all.map { |tz| tz.tzinfo.identifier } }, allow_blank: true
validates :time_zone_id,
allow_blank: true,
inclusion: {
in: ActiveSupport::TimeZone.all.map { |tz| tz.tzinfo.identifier }
}

def late?
!complete? && due_at < Date.today
!complete? && due_at < Time.zone.today
end

def complete?
Expand Down
6 changes: 3 additions & 3 deletions spec/factories/assignments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
points_earned 1
points_possible 1
order 1
due_at "2016-04-01 08:08:13"
completed_at "2016-04-01 08:08:13"
time_zone_id "MyString"
due_at '2016-04-01 08:08:13'
completed_at '2016-04-01 08:08:13'
time_zone_id 'MyString'
end
end
11 changes: 5 additions & 6 deletions spec/models/assignment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@
it { is_expected.to have_attribute :time_zone_id }

it 'is late when due_at is after today and not completed' do
subject.due_at = DateTime.new(2016,1,9)
expect(Date).to receive(:today).and_return DateTime.new(2016,1,10)
subject.due_at = DateTime.new.in_time_zone(2016, 1, 9)
expect(Date).to receive(:today).and_return DateTime.new(2016, 1, 10)
expect(subject.late?).to be true
end

it 'is not complete when no completion date is set' do
expect(subject.complete?).to be false
end

it "time_zone_id is a valid time_zone_id" do
subject.time_zone_id = "MarsTime"
it 'time_zone_id is a valid time_zone_id' do
subject.time_zone_id = 'MarsTime'
subject.valid?
expect(subject.errors[:time_zone_id]).to include "is not included in the list"
expect(subject.errors[:time_zone_id]).to include 'is not included in the list'
end

end
12 changes: 6 additions & 6 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@
it { is_expected.not_to validate_presence_of attribute }
end

it "validates the uniqueness of email_address" do
original = FactoryGirl.create(:user, email_address: "[email protected]")
it 'validates the uniqueness of email_address' do
original = FactoryGirl.create(:user, email_address: '[email protected]')
duplicate = FactoryGirl.build(:user, email_address: original.email_address)
duplicate.valid?
expect(duplicate.errors[:email_address]).to include "has already been taken"
expect(duplicate.errors[:email_address]).to include 'has already been taken'
end

it "validates the uniqueness of mobile_number" do
original = FactoryGirl.create(:user, mobile_number: "123-123-1234")
it 'validates the uniqueness of mobile_number' do
original = FactoryGirl.create(:user, mobile_number: '123-123-1234')
duplicate = FactoryGirl.build(:user, mobile_number: original.mobile_number)
duplicate.valid?
expect(duplicate.errors[:mobile_number]).to include "has already been taken"
expect(duplicate.errors[:mobile_number]).to include 'has already been taken'
end
end
6 changes: 3 additions & 3 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
# Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rails.env.production?
abort('The Rails environment is running in production mode!') if Rails.env.production?
require 'spec_helper'
require 'rspec/rails'
# Add additional requires below this line. Rails is not loaded until this point!
Expand Down Expand Up @@ -52,8 +52,8 @@
# arbitrary gems may also be filtered via:
# config.filter_gems_from_backtrace("gem name")

Shoulda::Matchers.configure do |config|
config.integrate do |with|
Shoulda::Matchers.configure do |c|
c.integrate do |with|
with.test_framework :rspec
with.library :rails
end
Expand Down
96 changes: 47 additions & 49 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,53 +40,51 @@
mocks.verify_partial_doubles = true
end

# The settings below are suggested to provide a good initial experience
# with RSpec, but feel free to customize to your heart's content.
=begin
# These two settings work together to allow you to limit a spec run
# to individual examples or groups you care about by tagging them with
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
# get run.
config.filter_run :focus
config.run_all_when_everything_filtered = true
# Allows RSpec to persist some state between runs in order to support
# the `--only-failures` and `--next-failure` CLI options. We recommend
# you configure your source control system to ignore this file.
config.example_status_persistence_file_path = "spec/examples.txt"
# Limits the available syntax to the non-monkey patched syntax that is
# recommended. For more details, see:
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
config.disable_monkey_patching!
# Many RSpec users commonly either run the entire suite or an individual
# file, and it's useful to allow more verbose output when running an
# individual spec file.
if config.files_to_run.one?
# Use the documentation formatter for detailed output,
# unless a formatter has already been configured
# (e.g. via a command-line flag).
config.default_formatter = 'doc'
end
# Print the 10 slowest examples and example groups at the
# end of the spec run, to help surface which specs are running
# particularly slow.
config.profile_examples = 10
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = :random
# Seed global randomization in this process using the `--seed` CLI option.
# Setting this allows you to use `--seed` to deterministically reproduce
# test failures related to randomization by passing the same `--seed` value
# as the one that triggered the failure.
Kernel.srand config.seed
=end
# The settings below are suggested to provide a good initial experience
# with RSpec, but feel free to customize to your heart's content.
# # These two settings work together to allow you to limit a spec run
# # to individual examples or groups you care about by tagging them with
# # `:focus` metadata. When nothing is tagged with `:focus`, all examples
# # get run.
# config.filter_run :focus
# config.run_all_when_everything_filtered = true
#
# # Allows RSpec to persist some state between runs in order to support
# # the `--only-failures` and `--next-failure` CLI options. We recommend
# # you configure your source control system to ignore this file.
# config.example_status_persistence_file_path = "spec/examples.txt"
#
# # Limits the available syntax to the non-monkey patched syntax that is
# # recommended. For more details, see:
# # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
# # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
# # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
# config.disable_monkey_patching!
#
# # Many RSpec users commonly either run the entire suite or an individual
# # file, and it's useful to allow more verbose output when running an
# # individual spec file.
# if config.files_to_run.one?
# # Use the documentation formatter for detailed output,
# # unless a formatter has already been configured
# # (e.g. via a command-line flag).
# config.default_formatter = 'doc'
# end
#
# # Print the 10 slowest examples and example groups at the
# # end of the spec run, to help surface which specs are running
# # particularly slow.
# config.profile_examples = 10
#
# # Run specs in random order to surface order dependencies. If you find an
# # order dependency and want to debug it, you can fix the order by providing
# # the seed, which is printed after each run.
# # --seed 1234
# config.order = :random
#
# # Seed global randomization in this process using the `--seed` CLI option.
# # Setting this allows you to use `--seed` to deterministically reproduce
# # test failures related to randomization by passing the same `--seed` value
# # as the one that triggered the failure.
# Kernel.srand config.seed
end

0 comments on commit d9245a8

Please sign in to comment.