diff --git a/lecture_5/homework/.rspec b/lecture_5/homework/.rspec new file mode 100644 index 00000000..c99d2e73 --- /dev/null +++ b/lecture_5/homework/.rspec @@ -0,0 +1 @@ +--require spec_helper diff --git a/lecture_5/homework/Gemfile b/lecture_5/homework/Gemfile index f10bbf07..d3db0ff7 100644 --- a/lecture_5/homework/Gemfile +++ b/lecture_5/homework/Gemfile @@ -5,6 +5,9 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" } ruby '2.6.2' +gem 'factory_bot_rails' +gem 'faker' +gem 'rubocop-rspec' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '~> 5.2.2' # Use pg as the database for Active Record diff --git a/lecture_5/homework/Gemfile.lock b/lecture_5/homework/Gemfile.lock index 411593e8..eaa3512c 100644 --- a/lecture_5/homework/Gemfile.lock +++ b/lecture_5/homework/Gemfile.lock @@ -1,25 +1,25 @@ GEM remote: https://rubygems.org/ specs: - actioncable (5.2.2.1) - actionpack (= 5.2.2.1) + actioncable (5.2.3) + actionpack (= 5.2.3) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailer (5.2.2.1) - actionpack (= 5.2.2.1) - actionview (= 5.2.2.1) - activejob (= 5.2.2.1) + actionmailer (5.2.3) + actionpack (= 5.2.3) + actionview (= 5.2.3) + activejob (= 5.2.3) mail (~> 2.5, >= 2.5.4) rails-dom-testing (~> 2.0) - actionpack (5.2.2.1) - actionview (= 5.2.2.1) - activesupport (= 5.2.2.1) + actionpack (5.2.3) + actionview (= 5.2.3) + activesupport (= 5.2.3) rack (~> 2.0) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.2.2.1) - activesupport (= 5.2.2.1) + actionview (5.2.3) + activesupport (= 5.2.3) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) @@ -29,36 +29,43 @@ GEM activemodel (>= 4.1, < 6) case_transform (>= 0.2) jsonapi-renderer (>= 0.1.1.beta1, < 0.3) - activejob (5.2.2.1) - activesupport (= 5.2.2.1) + activejob (5.2.3) + activesupport (= 5.2.3) globalid (>= 0.3.6) - activemodel (5.2.2.1) - activesupport (= 5.2.2.1) - activerecord (5.2.2.1) - activemodel (= 5.2.2.1) - activesupport (= 5.2.2.1) + activemodel (5.2.3) + activesupport (= 5.2.3) + activerecord (5.2.3) + activemodel (= 5.2.3) + activesupport (= 5.2.3) arel (>= 9.0) - activestorage (5.2.2.1) - actionpack (= 5.2.2.1) - activerecord (= 5.2.2.1) + activestorage (5.2.3) + actionpack (= 5.2.3) + activerecord (= 5.2.3) marcel (~> 0.3.1) - activesupport (5.2.2.1) + activesupport (5.2.3) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) arel (9.0.0) ast (2.4.0) - bootsnap (1.4.1) + bootsnap (1.4.3) msgpack (~> 1.0) builder (3.2.3) - byebug (11.0.0) + byebug (11.0.1) case_transform (0.2) activesupport concurrent-ruby (1.1.5) crass (1.0.4) diff-lcs (1.3) erubi (1.8.0) + factory_bot (5.0.2) + activesupport (>= 4.2.0) + factory_bot_rails (5.0.2) + factory_bot (~> 5.0.2) + railties (>= 4.2.0) + faker (1.9.3) + i18n (>= 0.7) ffi (1.10.0) globalid (0.4.2) activesupport (>= 4.2.0) @@ -84,38 +91,38 @@ GEM minitest (5.11.3) msgpack (1.2.9) nio4r (2.3.1) - nokogiri (1.10.1) + nokogiri (1.10.2) mini_portile2 (~> 2.4.0) parallel (1.17.0) - parser (2.6.2.0) + parser (2.6.2.1) ast (~> 2.4.0) pg (1.1.4) psych (3.1.0) - puma (3.12.0) - rack (2.0.6) + puma (3.12.1) + rack (2.0.7) rack-test (1.1.0) rack (>= 1.0, < 3) - rails (5.2.2.1) - actioncable (= 5.2.2.1) - actionmailer (= 5.2.2.1) - actionpack (= 5.2.2.1) - actionview (= 5.2.2.1) - activejob (= 5.2.2.1) - activemodel (= 5.2.2.1) - activerecord (= 5.2.2.1) - activestorage (= 5.2.2.1) - activesupport (= 5.2.2.1) + rails (5.2.3) + actioncable (= 5.2.3) + actionmailer (= 5.2.3) + actionpack (= 5.2.3) + actionview (= 5.2.3) + activejob (= 5.2.3) + activemodel (= 5.2.3) + activerecord (= 5.2.3) + activestorage (= 5.2.3) + activesupport (= 5.2.3) bundler (>= 1.3.0) - railties (= 5.2.2.1) + railties (= 5.2.3) sprockets-rails (>= 2.0.0) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) rails-html-sanitizer (1.0.4) loofah (~> 2.2, >= 2.2.2) - railties (5.2.2.1) - actionpack (= 5.2.2.1) - activesupport (= 5.2.2.1) + railties (5.2.3) + actionpack (= 5.2.3) + activesupport (= 5.2.3) method_source rake (>= 0.8.7) thor (>= 0.19.0, < 2.0) @@ -149,6 +156,8 @@ GEM rainbow (>= 2.2.2, < 4.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 1.6) + rubocop-rspec (1.32.0) + rubocop (>= 0.60.0) ruby-progressbar (1.10.0) ruby_dep (1.5.0) spring (2.0.2) @@ -179,12 +188,15 @@ DEPENDENCIES active_model_serializers bootsnap (>= 1.1.0) byebug + factory_bot_rails + faker listen (>= 3.0.5, < 3.2) pg puma (~> 3.11) rails (~> 5.2.2) rspec-rails rubocop + rubocop-rspec spring spring-watcher-listen (~> 2.0.0) tzinfo-data diff --git a/lecture_5/homework/app/controllers/buildings_controller.rb b/lecture_5/homework/app/controllers/buildings_controller.rb index 9b7e9677..da3a2239 100644 --- a/lecture_5/homework/app/controllers/buildings_controller.rb +++ b/lecture_5/homework/app/controllers/buildings_controller.rb @@ -1,7 +1,21 @@ # frozen_string_literal: true class BuildingsController < ApplicationController - def index; end + def index + render json: Building.all.order(:id), include: [:warriors] + end - def show; end + def show + render json: building, include: [:warriors] + end + + private + + def build_params + params.permit(:name,:granary) + end + + def building + @building ||= Building.find(params[:id]) + end end diff --git a/lecture_5/homework/app/models/building.rb b/lecture_5/homework/app/models/building.rb index ee460ad6..f165f041 100644 --- a/lecture_5/homework/app/models/building.rb +++ b/lecture_5/homework/app/models/building.rb @@ -4,5 +4,6 @@ class Building < ApplicationRecord has_many :warriors, dependent: :nullify validates :granary, presence: true, - numerically: { greater_than_or_equal_to: 0, only_integer: true } + numericality: { greater_than_or_equal_to: 0, only_integer: true } + validates :siege_ability, presence: true, numericality: { greater_than_or_equal_to: 0 } end diff --git a/lecture_5/homework/app/models/warrior.rb b/lecture_5/homework/app/models/warrior.rb index eacdc13f..fe16b77d 100644 --- a/lecture_5/homework/app/models/warrior.rb +++ b/lecture_5/homework/app/models/warrior.rb @@ -14,4 +14,41 @@ class Warrior < ApplicationRecord scope :alive, -> { where('death_date IS NULL') } scope :dead, -> { where('death_date IS NOT NULL') } + + after_create :update_siege + before_update :update_prev_building + # cant put same if: :building_id_changed? since it will always return false + after_update :update_siege_after + # after_commit :update_siege_after + after_destroy :update_siege + + def update_siege + # call after warrior already was asigned to building list after create,update + # works for delete as well + Reports::SiegeReport.call(building: building) if building + end + + # it seems like rspec didnt invoke those callbacks + # when i was testing manually it works + # probably messed up in factory and tests :( + def update_siege_after + if prev_building_id + # if warrior changed his building run this on both + # since in that moment he is no longer in old list , rather in new building + # so this way i can keep both old and new buildings updated + # puts "prev building: #{prev_building_id} current: #{building_id}" + Reports::SiegeReport.call(building: Building.find(prev_building_id)) + Reports::SiegeReport.call(building: Building.find(building_id)) + # set this to nil to prevent callback invoking from random update + update_column(:prev_building_id, nil) + end + end + + def update_prev_building + # if warrior is changing his buildings + if building_id_was != building_id + # save this attribute wihtout triggering callbacks + update_column(:prev_building_id, building_id_was) + end + end end diff --git a/lecture_5/homework/app/serializers/building_serializer.rb b/lecture_5/homework/app/serializers/building_serializer.rb index 899c9aa0..784d9e97 100644 --- a/lecture_5/homework/app/serializers/building_serializer.rb +++ b/lecture_5/homework/app/serializers/building_serializer.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class BuildingSerializer < ActiveModel::Serializer - attributes :name + attributes :name, :siege_ability, :granary has_many :warriors end diff --git a/lecture_5/homework/app/services/reports/siege_report.rb b/lecture_5/homework/app/services/reports/siege_report.rb index 16a0b3a4..5b5b9fec 100644 --- a/lecture_5/homework/app/services/reports/siege_report.rb +++ b/lecture_5/homework/app/services/reports/siege_report.rb @@ -2,11 +2,21 @@ module Reports class SiegeReport - def initialize(building:) - end + def self.call(building:) + # this should stop the method if getting null + return unless building - def call - raise NotImprementedYet + # bulding cant be defended without warriors + if building.warriors.any? + warriors_count = building.warriors.where(type: 'Warriors::Samurai').count + hussar_count = building.warriors.where(type: 'Warriors::Hussar').count + total_rice_need = warriors_count + hussar_count * 2 + building.default_rice_need + siege_ability = building.granary / total_rice_need + building.siege_ability = siege_ability + else + building.siege_ability = 0 + end + building.save! end end end diff --git a/lecture_5/homework/db/migrate/20190415130731_add_siege_ability.rb b/lecture_5/homework/db/migrate/20190415130731_add_siege_ability.rb new file mode 100644 index 00000000..1affa82b --- /dev/null +++ b/lecture_5/homework/db/migrate/20190415130731_add_siege_ability.rb @@ -0,0 +1,6 @@ +class AddSiegeAbility < ActiveRecord::Migration[5.2] + def change + add_column :buildings, :siege_ability, :integer, default: 0, null: false + + end +end diff --git a/lecture_5/homework/db/migrate/20190415133246_add_default_rice_need.rb b/lecture_5/homework/db/migrate/20190415133246_add_default_rice_need.rb new file mode 100644 index 00000000..84e04edd --- /dev/null +++ b/lecture_5/homework/db/migrate/20190415133246_add_default_rice_need.rb @@ -0,0 +1,8 @@ +class AddDefaultRiceNeed < ActiveRecord::Migration[5.2] + def change + add_column :buildings, :default_rice_need, :integer, default: 0 + + Buildings::Stronghold.find_each { |building| update_attribute(:default_rice_need,10) } + Building.find_each { |building| Reports::SiegeReport.check_siege_ability(building: building) } + end +end diff --git a/lecture_5/homework/db/migrate/20190417075546_add_previous_building_id.rb b/lecture_5/homework/db/migrate/20190417075546_add_previous_building_id.rb new file mode 100644 index 00000000..09719822 --- /dev/null +++ b/lecture_5/homework/db/migrate/20190417075546_add_previous_building_id.rb @@ -0,0 +1,6 @@ +class AddPreviousBuildingId < ActiveRecord::Migration[5.2] + def change + add_column :warriors, :prev_building_id, :integer + + end +end diff --git a/lecture_5/homework/db/schema.rb b/lecture_5/homework/db/schema.rb index 13f968ab..725af4c9 100644 --- a/lecture_5/homework/db/schema.rb +++ b/lecture_5/homework/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2019_04_05_090544) do +ActiveRecord::Schema.define(version: 2019_04_17_075546) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -20,6 +20,9 @@ t.string "type", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.integer "granary", default: 0, null: false + t.integer "siege_ability", default: 0, null: false + t.integer "default_rice_need", default: 0 end create_table "clans", force: :cascade do |t| @@ -53,6 +56,7 @@ t.string "type", default: "Warriors::Samurai", null: false t.bigint "building_id" t.string "preferred_weapon_kind" + t.integer "prev_building_id" t.index ["building_id"], name: "index_warriors_on_building_id" t.index ["clan_id"], name: "index_warriors_on_clan_id" t.index ["name"], name: "index_warriors_on_name", unique: true, where: "(death_date IS NULL)" diff --git a/lecture_5/homework/db/seeds.rb b/lecture_5/homework/db/seeds.rb index 66a120fd..d44633c5 100644 --- a/lecture_5/homework/db/seeds.rb +++ b/lecture_5/homework/db/seeds.rb @@ -3,13 +3,15 @@ first_clan = Clan.create!(name: 'The very first clan') training_clan = Clan.create!(name: 'Training clan') -stronghold = Buildings::Stronghold.create!(name: 'Main stronghold', granary: 5000) +stronghold = Buildings::Stronghold.create!(name: 'Main stronghold', granary: 5000,default_rice_need: 10) +stronghold_empty = Buildings::Stronghold.create!(name: 'Empty stronghold', granary: 5000,default_rice_need: 10) northern_wall = Buildings::Walls.create!(name: 'Northern wall', granary: 100) southern_wall = Buildings::Walls.create!(name: 'Southern wall', granary: 100) samurai_1 = Warriors::Samurai.create!(name: '曽山大輝', clan: first_clan, death_date: 1.week.ago) samurai_2 = Warriors::Samurai.create!(name: '曽山大輝', clan: first_clan, building: stronghold) samurai_3 = Warriors::Samurai.create!(name: '澄田清', clan: training_clan, building: stronghold) +hussar_4 = Warriors::Hussar.create!(name: 'Banzai Hito', clan: first_clan, building: stronghold) hussar_1 = Warriors::Hussar.create!(name: 'Idzi Kwiatkowski', clan: first_clan, building: northern_wall) hussar_2 = Warriors::Hussar.create!(name: 'Świętopełk Król', clan: training_clan, building: southern_wall) diff --git a/lecture_5/homework/spec/controllers/buildings_controller_spec.rb b/lecture_5/homework/spec/controllers/buildings_controller_spec.rb new file mode 100644 index 00000000..396298cd --- /dev/null +++ b/lecture_5/homework/spec/controllers/buildings_controller_spec.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe BuildingsController, type: :controller do + subject(:building) { create(:building) } + describe 'it get all buildings' do + it 'responds with 200' do + get 'index' + expect(response).to have_http_status(200) + end + end + + describe 'it should find some building' do + it 'responds with 200' do + get :show, params: { id: building.id } + expect(response).to have_http_status(200) + end + end + + describe 'it shows no building found' do + it 'responds with 404' do + get :show, params: { id: 999 } + expect(response).to have_http_status(404) + end + end +end diff --git a/lecture_5/homework/spec/factories/buildings.rb b/lecture_5/homework/spec/factories/buildings.rb new file mode 100644 index 00000000..c24cde60 --- /dev/null +++ b/lecture_5/homework/spec/factories/buildings.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :building do + name { Faker::Games::Witcher.location } + type { 'Buildings::Walls' } + granary { 500 } + end +end diff --git a/lecture_5/homework/spec/factories/clans.rb b/lecture_5/homework/spec/factories/clans.rb new file mode 100644 index 00000000..91af847e --- /dev/null +++ b/lecture_5/homework/spec/factories/clans.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :clan do + name { Faker::Games::Witcher.school } + end +end diff --git a/lecture_5/homework/spec/factories/warrior.rb b/lecture_5/homework/spec/factories/warrior.rb new file mode 100644 index 00000000..5efc9263 --- /dev/null +++ b/lecture_5/homework/spec/factories/warrior.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :warrior do + name { Faker::Games::Witcher.character } + association :building + association :clan + + trait :samurai do + type { 'Warriors::Samurai' } + end + + trait :hussar do + type { 'Warriors::Hussar' } + end + end +end diff --git a/lecture_5/homework/spec/helpers/reports/siege_report_spec.rb b/lecture_5/homework/spec/helpers/reports/siege_report_spec.rb new file mode 100644 index 00000000..7da417b0 --- /dev/null +++ b/lecture_5/homework/spec/helpers/reports/siege_report_spec.rb @@ -0,0 +1,72 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe Reports::SiegeReport, type: :helper do + subject(:clan) { create(:clan) } + subject(:building) { create(:building) } + subject(:building2) { create(:building) } + context(' valid data ') do + it 'set building siege_value to be 250' do + w1 = create(:warrior, :samurai, clan: clan, building: building) + w2 = create(:warrior, :samurai, clan: clan, building: building) + # Reports::SiegeReport.call(building: building) + expect(building.siege_ability).to eq(250) + end + + it 'set building siege_value to be 500 after one warrior was destroyed' do + w1 = create(:warrior, :samurai, clan: clan, building: building) + w2 = create(:warrior, :samurai, clan: clan, building: building) + # Reports::SiegeReport.call(building: building) + w2.destroy! + expect(building.siege_ability).to eq(500) + end + + it 'set building siege_value to be 0 after both warriors was destroyed' do + w1 = create(:warrior, :samurai, clan: clan, building: building) + w2 = create(:warrior, :samurai, clan: clan, building: building) + # Reports::SiegeReport.call(building: building) + w1.destroy + w2.destroy + expect(building.siege_ability).to eq(0) + end + + # fail should 500 instead of 250 + it 'set building siege_value to be 250 after building change' do + w1 = create(:warrior, :samurai, clan: clan, building: building) + w2 = create(:warrior, :samurai, clan: clan, building: building2) + Reports::SiegeReport.call(building: building) + w2.update(building: building) + expect(building.siege_ability).to eq(500) + end + + # Fail got 250 instead of 500 + it 'set building siege_value to be 500 after building change' do + w1 = create(:warrior, :samurai, clan: clan, building: building) + w2 = create(:warrior, :samurai, clan: clan, building: building) + Reports::SiegeReport.call(building: building) + w2.update!(building: building2) + + expect(building.siege_ability).to eq(250) + end + # Fail got 500 instead of 0 + it 'set building siege_value to be 0 after building2 change' do + w1 = create(:warrior, :samurai, clan: clan, building: building) + w2 = create(:warrior, :samurai, clan: clan, building: building2) + Reports::SiegeReport.call(building: building) + w2.update!(building: building) + expect(building2.siege_ability).to eq(500) + end + end + + context(' invalid data ') do + it 'should return nothing' do + expect(Reports::SiegeReport.call(building: nil)).to be_nil + end + + it 'should set building to 0 siege_ability' do + Reports::SiegeReport.call(building: building) + expect(building.siege_ability).to eq(0) + end + end +end diff --git a/lecture_5/homework/spec/rails_helper.rb b/lecture_5/homework/spec/rails_helper.rb new file mode 100644 index 00000000..e2cb8518 --- /dev/null +++ b/lecture_5/homework/spec/rails_helper.rb @@ -0,0 +1,64 @@ +# frozen_string_literal: true + +# This file is copied to spec/ when you run 'rails generate rspec:install' +require 'spec_helper' +ENV['RAILS_ENV'] ||= 'test' +require File.expand_path('../config/environment', __dir__) +# Prevent database truncation if the environment is production +abort('The Rails environment is running in production mode!') if Rails.env.production? +require 'rspec/rails' +# Add additional requires below this line. Rails is not loaded until this point! + +# Requires supporting ruby files with custom matchers and macros, etc, in +# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are +# run as spec files by default. This means that files in spec/support that end +# in _spec.rb will both be required and run as specs, causing the specs to be +# run twice. It is recommended that you do not name files matching this glob to +# end with _spec.rb. You can configure this pattern with the --pattern +# option on the command line or in ~/.rspec, .rspec or `.rspec-local`. +# +# The following line is provided for convenience purposes. It has the downside +# of increasing the boot-up time by auto-requiring all files in the support +# directory. Alternatively, in the individual `*_spec.rb` files, manually +# require only the support files necessary. +# +# Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f } + +# Checks for pending migrations and applies them before tests are run. +# If you are not using ActiveRecord, you can remove these lines. +begin + ActiveRecord::Migration.maintain_test_schema! +rescue ActiveRecord::PendingMigrationError => e + puts e.to_s.strip + exit 1 +end +RSpec.configure do |config| + config.include FactoryBot::Syntax::Methods + # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures + config.fixture_path = "#{::Rails.root}/spec/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 + # instead of true. + config.use_transactional_fixtures = true + + # RSpec Rails can automatically mix in different behaviours to your tests + # based on their file location, for example enabling you to call `get` and + # `post` in specs under `spec/controllers`. + # + # You can disable this behaviour by removing the line below, and instead + # explicitly tag your specs with their type, e.g.: + # + # RSpec.describe UsersController, :type => :controller do + # # ... + # end + # + # The different available types are documented in the features, such as in + # https://relishapp.com/rspec/rspec-rails/docs + config.infer_spec_type_from_file_location! + + # Filter lines from Rails gems in backtraces. + config.filter_rails_from_backtrace! + # arbitrary gems may also be filtered via: + # config.filter_gems_from_backtrace("gem name") +end diff --git a/lecture_5/homework/spec/spec_helper.rb b/lecture_5/homework/spec/spec_helper.rb new file mode 100644 index 00000000..01f7c974 --- /dev/null +++ b/lecture_5/homework/spec/spec_helper.rb @@ -0,0 +1,96 @@ +# frozen_string_literal: true + +# This file was generated by the `rails generate rspec:install` command. Conventionally, all +# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. +# The generated `.rspec` file contains `--require spec_helper` which will cause +# this file to always be loaded, without a need to explicitly require it in any +# files. +# +# Given that it is always loaded, you are encouraged to keep this file as +# light-weight as possible. Requiring heavyweight dependencies from this file +# will add to the boot time of your test suite on EVERY test run, even for an +# individual file that may not need all of that loaded. Instead, consider making +# a separate helper file that requires the additional dependencies and performs +# the additional setup, and require it from the spec files that actually need +# it. +# +# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +RSpec.configure do |config| + # rspec-expectations config goes here. You can use an alternate + # assertion/expectation library such as wrong or the stdlib/minitest + # assertions if you prefer. + config.expect_with :rspec do |expectations| + # This option will default to `true` in RSpec 4. It makes the `description` + # and `failure_message` of custom matchers include text for helper methods + # defined using `chain`, e.g.: + # be_bigger_than(2).and_smaller_than(4).description + # # => "be bigger than 2 and smaller than 4" + # ...rather than: + # # => "be bigger than 2" + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + # rspec-mocks config goes here. You can use an alternate test double + # library (such as bogus or mocha) by changing the `mock_with` option here. + config.mock_with :rspec do |mocks| + # Prevents you from mocking or stubbing a method that does not exist on + # a real object. This is generally recommended, and will default to + # `true` in RSpec 4. + mocks.verify_partial_doubles = true + end + + # This option will default to `:apply_to_host_groups` in RSpec 4 (and will + # have no way to turn it off -- the option exists only for backwards + # compatibility in RSpec 3). It causes shared context metadata to be + # inherited by the metadata hash of host groups and examples, rather than + # triggering implicit auto-inclusion in groups with matching metadata. + config.shared_context_metadata_behavior = :apply_to_host_groups + + # The settings below are suggested to provide a good initial experience + # with RSpec, but feel free to customize to your heart's content. + # # This allows 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. RSpec also provides + # # aliases for `it`, `describe`, and `context` that include `:focus` + # # metadata: `fit`, `fdescribe` and `fcontext`, respectively. + # config.filter_run_when_matching :focus + # + # # 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