From cd90aab4600ec73dc61a39e8678ed2f03e8976c1 Mon Sep 17 00:00:00 2001 From: Kirill Oleynik Date: Mon, 22 Aug 2016 10:24:34 +0300 Subject: [PATCH] Feature: user can see empty cart --- .gitignore | 1 + .rspec | 2 + .ruby-version | 1 + Gemfile.lock | 126 ++++++++++++++++++ .../shopping_cart/orders_controller.rb | 47 +++++++ app/models/shopping_cart/order.rb | 75 +++++++++++ .../shopping_cart/application.html.erb | 14 -- .../shopping_cart/application.html.haml | 10 ++ .../orders/_empty_cart.html.haml | 3 + .../shopping_cart/orders/_form.html.haml | 36 +++++ app/views/shopping_cart/orders/edit.html.haml | 8 ++ config/locales/shopping_cart.en.yml | 31 +++++ config/routes.rb | 4 + ...14135512_create_shopping_cart_addresses.rb | 15 +++ ...0814135612_create_shopping_cart_coupons.rb | 10 ++ ...35700_create_shopping_cart_credit_cards.rb | 14 ++ ...4135728_create_shopping_cart_deliveries.rb | 9 ++ ...135816_create_shopping_cart_order_items.rb | 10 ++ ...60814135925_create_shopping_cart_orders.rb | 15 +++ lib/shopping_cart.rb | 1 + shopping_cart.gemspec | 5 +- spec/dummy/config/routes.rb | 2 +- spec/dummy/db/schema.rb | 74 ++++++++++ spec/spec_helper.rb | 103 ++++++++++++++ 24 files changed, 599 insertions(+), 17 deletions(-) create mode 100644 .rspec create mode 100644 .ruby-version create mode 100644 Gemfile.lock create mode 100644 app/controllers/shopping_cart/orders_controller.rb create mode 100644 app/models/shopping_cart/order.rb delete mode 100644 app/views/layouts/shopping_cart/application.html.erb create mode 100644 app/views/layouts/shopping_cart/application.html.haml create mode 100644 app/views/shopping_cart/orders/_empty_cart.html.haml create mode 100644 app/views/shopping_cart/orders/_form.html.haml create mode 100644 app/views/shopping_cart/orders/edit.html.haml create mode 100644 config/locales/shopping_cart.en.yml create mode 100644 db/migrate/20160814135512_create_shopping_cart_addresses.rb create mode 100644 db/migrate/20160814135612_create_shopping_cart_coupons.rb create mode 100644 db/migrate/20160814135700_create_shopping_cart_credit_cards.rb create mode 100644 db/migrate/20160814135728_create_shopping_cart_deliveries.rb create mode 100644 db/migrate/20160814135816_create_shopping_cart_order_items.rb create mode 100644 db/migrate/20160814135925_create_shopping_cart_orders.rb create mode 100644 spec/dummy/db/schema.rb create mode 100644 spec/spec_helper.rb diff --git a/.gitignore b/.gitignore index aae7f11..c4ee1db 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ spec/dummy/db/*.sqlite3 spec/dummy/db/*.sqlite3-journal spec/dummy/log/*.log spec/dummy/tmp/ +.ruby-gemset diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..83e16f8 --- /dev/null +++ b/.rspec @@ -0,0 +1,2 @@ +--color +--require spec_helper diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..2bf1c1c --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +2.3.1 diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..f5c4695 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,126 @@ +PATH + remote: . + specs: + shopping_cart (0.1.0) + aasm + haml + pg + rails (~> 5.0.0, >= 5.0.0.1) + +GEM + remote: https://rubygems.org/ + specs: + aasm (4.11.0) + actioncable (5.0.0.1) + actionpack (= 5.0.0.1) + nio4r (~> 1.2) + websocket-driver (~> 0.6.1) + actionmailer (5.0.0.1) + actionpack (= 5.0.0.1) + actionview (= 5.0.0.1) + activejob (= 5.0.0.1) + mail (~> 2.5, >= 2.5.4) + rails-dom-testing (~> 2.0) + actionpack (5.0.0.1) + actionview (= 5.0.0.1) + activesupport (= 5.0.0.1) + rack (~> 2.0) + rack-test (~> 0.6.3) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + actionview (5.0.0.1) + activesupport (= 5.0.0.1) + builder (~> 3.1) + erubis (~> 2.7.0) + rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.2) + activejob (5.0.0.1) + activesupport (= 5.0.0.1) + globalid (>= 0.3.6) + activemodel (5.0.0.1) + activesupport (= 5.0.0.1) + activerecord (5.0.0.1) + activemodel (= 5.0.0.1) + activesupport (= 5.0.0.1) + arel (~> 7.0) + activesupport (5.0.0.1) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (~> 0.7) + minitest (~> 5.1) + tzinfo (~> 1.1) + arel (7.1.1) + builder (3.2.2) + concurrent-ruby (1.0.2) + erubis (2.7.0) + globalid (0.3.7) + activesupport (>= 4.1.0) + haml (4.0.7) + tilt + i18n (0.7.0) + loofah (2.0.3) + nokogiri (>= 1.5.9) + mail (2.6.4) + mime-types (>= 1.16, < 4) + method_source (0.8.2) + mime-types (3.1) + mime-types-data (~> 3.2015) + mime-types-data (3.2016.0521) + mini_portile2 (2.1.0) + minitest (5.9.0) + nio4r (1.2.1) + nokogiri (1.6.8) + mini_portile2 (~> 2.1.0) + pkg-config (~> 1.1.7) + pg (0.18.4) + pkg-config (1.1.7) + rack (2.0.1) + rack-test (0.6.3) + rack (>= 1.0) + rails (5.0.0.1) + actioncable (= 5.0.0.1) + actionmailer (= 5.0.0.1) + actionpack (= 5.0.0.1) + actionview (= 5.0.0.1) + activejob (= 5.0.0.1) + activemodel (= 5.0.0.1) + activerecord (= 5.0.0.1) + activesupport (= 5.0.0.1) + bundler (>= 1.3.0, < 2.0) + railties (= 5.0.0.1) + sprockets-rails (>= 2.0.0) + rails-dom-testing (2.0.1) + activesupport (>= 4.2.0, < 6.0) + nokogiri (~> 1.6.0) + rails-html-sanitizer (1.0.3) + loofah (~> 2.0) + railties (5.0.0.1) + actionpack (= 5.0.0.1) + activesupport (= 5.0.0.1) + method_source + rake (>= 0.8.7) + thor (>= 0.18.1, < 2.0) + rake (11.2.2) + sprockets (3.7.0) + concurrent-ruby (~> 1.0) + rack (> 1, < 3) + sprockets-rails (3.1.1) + actionpack (>= 4.0) + activesupport (>= 4.0) + sprockets (>= 3.0.0) + thor (0.19.1) + thread_safe (0.3.5) + tilt (2.0.5) + tzinfo (1.2.2) + thread_safe (~> 0.1) + websocket-driver (0.6.4) + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.2) + +PLATFORMS + ruby + +DEPENDENCIES + shopping_cart! + +BUNDLED WITH + 1.12.5 diff --git a/app/controllers/shopping_cart/orders_controller.rb b/app/controllers/shopping_cart/orders_controller.rb new file mode 100644 index 0000000..9724dc3 --- /dev/null +++ b/app/controllers/shopping_cart/orders_controller.rb @@ -0,0 +1,47 @@ +module ShoppingCart + class OrdersController < ApplicationController + # before_action :set_order, only: [:update, :destroy] + + # decorates_assigned :order + + # def index + # @orders = current_customer.orders + # end + # + # def show + # @order = Order.with_books.find_by(id: params[:id]) + # back_to_shop('Order') unless @order + # end + + def edit + # @order = current_customer.orders.in_progress.decorate.first + @order = ShoppingCart::Order.where(user_id: current_user.id).in_progress.first + end + + # def update + # UpdateOrder.call(@order, params) do + # on(:ok) { updated_notice('Order') } + # on(:invalid) { update_error('Order') } + # end + # redirect_to cart_path + # end + # + # def destroy + # @order.destroy ? deleted_notice('Order') : delete_error('Order') + # redirect_to cart_path + # end + # + # def create + # CreateOrder.call(params) do + # on(:ok) { redirect_to cart_path } + # on(:invalid) { add_book_failed } + # end + # end + + # private + + # def set_order + # @order = Order.find_by_id params[:id] + # end + end +end diff --git a/app/models/shopping_cart/order.rb b/app/models/shopping_cart/order.rb new file mode 100644 index 0000000..b31c78b --- /dev/null +++ b/app/models/shopping_cart/order.rb @@ -0,0 +1,75 @@ +require 'aasm' + +module ShoppingCart + class Order < ApplicationRecord + # has_many :order_items, dependent: :destroy + # belongs_to :customer + # belongs_to :credit_card + # belongs_to :delivery + # has_one :coupon, dependent: :destroy + # has_one :order_shipping, + # -> { where addressable_type: 'order_shipping' }, + # class_name: Address, foreign_key: :addressable_id, + # dependent: :destroy + # has_one :order_billing, + # -> { where addressable_type: 'order_billing' }, + # class_name: Address, foreign_key: :addressable_id, + # dependent: :destroy + + # accepts_nested_attributes_for :order_items, allow_destroy: true + # + # after_validation :update_total + + include AASM + # attr_accessor :active_admin_requested_event + aasm column: :state, whiny_transitions: false do + state :in_progress, initial: true + state :processing + state :in_delivery + state :delivered + state :canceled + + event :completed do + transitions from: :in_progress, to: :processing + end + + event :sent_to_client do + transitions from: :processing, to: :in_delivery + end + + event :delivered do + transitions from: :in_delivery, to: :delivered + end + + event :canceled do + transitions from: [:processing, :in_delivery], to: :canceled + end + end + + # scope :with_books, -> { includes(order_items: :book) } + # + # def add_item(book_id, quantity = 1) + # item = order_items.find_by(book_id: book_id) + # if item + # item.update_amount(quantity) + # else + # order_items.create(quantity: quantity, book_id: book_id) + # end + # end + # + # def update_total + # return if errors.any? + # new_total = order_items.map(&:item_total).sum + # new_total -= (new_total * coupon.discount / 100) if coupon + # self.total = new_total + # end + # + # def destroy_if_orphant + # self.destroy if order_items.count.zero? + # end + # + # def has_all_data? + # order_billing && order_shipping && credit_card && delivery + # end + end +end diff --git a/app/views/layouts/shopping_cart/application.html.erb b/app/views/layouts/shopping_cart/application.html.erb deleted file mode 100644 index be3aa29..0000000 --- a/app/views/layouts/shopping_cart/application.html.erb +++ /dev/null @@ -1,14 +0,0 @@ - - - - Shopping cart - <%= stylesheet_link_tag "shopping_cart/application", media: "all" %> - <%= javascript_include_tag "shopping_cart/application" %> - <%= csrf_meta_tags %> - - - -<%= yield %> - - - diff --git a/app/views/layouts/shopping_cart/application.html.haml b/app/views/layouts/shopping_cart/application.html.haml new file mode 100644 index 0000000..7ccc05f --- /dev/null +++ b/app/views/layouts/shopping_cart/application.html.haml @@ -0,0 +1,10 @@ +!!! +%html + %head + %meta{:content => "text/html; charset=UTF-8", "http-equiv" => "Content-Type"}/ + %title Shopping cart + = stylesheet_link_tag "shopping_cart/application", media: "all" + = javascript_include_tag "shopping_cart/application" + = csrf_meta_tags + %body + = yield diff --git a/app/views/shopping_cart/orders/_empty_cart.html.haml b/app/views/shopping_cart/orders/_empty_cart.html.haml new file mode 100644 index 0000000..2195b65 --- /dev/null +++ b/app/views/shopping_cart/orders/_empty_cart.html.haml @@ -0,0 +1,3 @@ +.text-center + %p.lead= I18n.t('cart.empty_cart') + -# = back_to_shop_link diff --git a/app/views/shopping_cart/orders/_form.html.haml b/app/views/shopping_cart/orders/_form.html.haml new file mode 100644 index 0000000..56ba6f1 --- /dev/null +++ b/app/views/shopping_cart/orders/_form.html.haml @@ -0,0 +1,36 @@ += form_for order do |f| + %table.table#current_order + %thead + %tr + %th.lead.text-center{colspan:2}= t('index.book') + %th.lead.text-center= t('index.quantity') + %th.lead.text-center= t('index.price') + %th.lead.text-center= t('index.total') + %tbody.text-center + = f.fields_for :order_items do |oi| + %tr + %td{width:"15%"}= image_tag oi.object.book.cover.small + %td.text-left{width:'55%'} + %h4= link_to oi.object.book.title, oi.object.book + %p= oi.object.book.preview + %td{width:'10%'}= oi.number_field :quantity, class: 'form-control' + %td{width:'10%'}= number_to_currency oi.object.book.price + %td{width:'10%'}= delete_item_link oi.object.id + %tr.lead + %td{colspan:3} + %td.text-right + %p= t('cart.discount') if order.coupon + %p= t('cart.total') + %td + %p= order.discount if order.coupon + %p= order.total_in_currency + %tr + %td.text-center= empty_cart_link order + %td.text-left= continue_shopping_link + %td + = f.fields_for :coupon do |c| + = c.text_field :code, class: 'form-control', + placeholder: (order.coupon ? order.coupon.code : t('coupon_code')), + disabled: (true if order.coupon) + %td.text-center= f.submit t('orders.edit.update'), class: 'btn btn-success' + %td.text-center= link_to_checkout diff --git a/app/views/shopping_cart/orders/edit.html.haml b/app/views/shopping_cart/orders/edit.html.haml new file mode 100644 index 0000000..3427e78 --- /dev/null +++ b/app/views/shopping_cart/orders/edit.html.haml @@ -0,0 +1,8 @@ +.raw + .col-md-12 + %h1.page-header= I18n.t('cart.page_title') + .well + - if @order + = render partial: 'form', locals: {order: @order} + - else + = render partial: 'empty_cart' diff --git a/config/locales/shopping_cart.en.yml b/config/locales/shopping_cart.en.yml new file mode 100644 index 0000000..1e4cac4 --- /dev/null +++ b/config/locales/shopping_cart.en.yml @@ -0,0 +1,31 @@ +en: + # states: + # in_progress: "In progress" + # processing: "Processing" + # in_delivery: "In delivery" + # delivered: "Delivered" + cart: + page_title: "Cart" + empty_cart: "Nothing added to your order." + # total: "Order total:" + # back_to_shop: "Back to Shop" + # deleted: "Your order deleted successfuly" + # delete_error: "Something went wrong and your order was not deleted. Please, try again." + # index: + # orders_title: "Your orders" + # book: "Book" + # price: "Price" + # quantity: "QTY" + # total: "Total" + # to_cart: "Go to cart" + # subtotal: "Subtotal:" + # number: "Number" + # completed_at: "Completed at" + # total: "Total" + # view: "View order" + # no_orders: "You still have not ordered anything" + # back_to_shop: "Back to Shop" + # show: + # title: "Order information" + # order_name_html: "Order %{num} %{state}" + # back_to_orders: "Back to Orders" diff --git a/config/routes.rb b/config/routes.rb index 0ed7948..ce9c030 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,2 +1,6 @@ ShoppingCart::Engine.routes.draw do + get '/', to: 'orders#edit' + resources :orders, only: [:update, :create, :destroy] + resources :order_items, only: [:destroy] + resources :checkout end diff --git a/db/migrate/20160814135512_create_shopping_cart_addresses.rb b/db/migrate/20160814135512_create_shopping_cart_addresses.rb new file mode 100644 index 0000000..1838b04 --- /dev/null +++ b/db/migrate/20160814135512_create_shopping_cart_addresses.rb @@ -0,0 +1,15 @@ +class CreateShoppingCartAddresses < ActiveRecord::Migration[5.0] + def change + create_table :shopping_cart_addresses do |t| + t.string :street + t.string :zipcode + t.string :city + t.string :phone + t.string :first_name + t.string :last_name + t.string :country_code + t.belongs_to :order, index: true + t.timestamps + end + end +end diff --git a/db/migrate/20160814135612_create_shopping_cart_coupons.rb b/db/migrate/20160814135612_create_shopping_cart_coupons.rb new file mode 100644 index 0000000..c5bbbe0 --- /dev/null +++ b/db/migrate/20160814135612_create_shopping_cart_coupons.rb @@ -0,0 +1,10 @@ +class CreateShoppingCartCoupons < ActiveRecord::Migration[5.0] + def change + create_table :shopping_cart_coupons do |t| + t.string :code + t.float :discount + t.belongs_to :order, index: true + t.timestamps + end + end +end diff --git a/db/migrate/20160814135700_create_shopping_cart_credit_cards.rb b/db/migrate/20160814135700_create_shopping_cart_credit_cards.rb new file mode 100644 index 0000000..7dc4364 --- /dev/null +++ b/db/migrate/20160814135700_create_shopping_cart_credit_cards.rb @@ -0,0 +1,14 @@ +class CreateShoppingCartCreditCards < ActiveRecord::Migration[5.0] + def change + create_table :shopping_cart_credit_cards do |t| + t.string :number + t.string :cvv + t.integer :year + t.integer :month + t.string :first_name + t.string :last_name + t.belongs_to :order, index: true + t.timestamps + end + end +end diff --git a/db/migrate/20160814135728_create_shopping_cart_deliveries.rb b/db/migrate/20160814135728_create_shopping_cart_deliveries.rb new file mode 100644 index 0000000..669686f --- /dev/null +++ b/db/migrate/20160814135728_create_shopping_cart_deliveries.rb @@ -0,0 +1,9 @@ +class CreateShoppingCartDeliveries < ActiveRecord::Migration[5.0] + def change + create_table :shopping_cart_deliveries do |t| + t.string :title + t.float :price + t.timestamps + end + end +end diff --git a/db/migrate/20160814135816_create_shopping_cart_order_items.rb b/db/migrate/20160814135816_create_shopping_cart_order_items.rb new file mode 100644 index 0000000..4b89eef --- /dev/null +++ b/db/migrate/20160814135816_create_shopping_cart_order_items.rb @@ -0,0 +1,10 @@ +class CreateShoppingCartOrderItems < ActiveRecord::Migration[5.0] + def change + create_table :shopping_cart_order_items do |t| + t.integer :quantity + t.belongs_to :order, index: true + t.references :productable, polymorphic: true, index: {name: 'productable'} + t.timestamps + end + end +end diff --git a/db/migrate/20160814135925_create_shopping_cart_orders.rb b/db/migrate/20160814135925_create_shopping_cart_orders.rb new file mode 100644 index 0000000..b73f70f --- /dev/null +++ b/db/migrate/20160814135925_create_shopping_cart_orders.rb @@ -0,0 +1,15 @@ +class CreateShoppingCartOrders < ActiveRecord::Migration[5.0] + def change + enable_extension 'uuid-ossp' + create_table :shopping_cart_orders do |t| + t.float :total + t.string :state + t.uuid :number, default: "uuid_generate_v4()" + t.belongs_to :delivery, index: true + t.belongs_to :credit_card, index: true + t.belongs_to :user, index: true + t.timestamp :completed_at + t.timestamps + end + end +end diff --git a/lib/shopping_cart.rb b/lib/shopping_cart.rb index 6625325..0831dad 100644 --- a/lib/shopping_cart.rb +++ b/lib/shopping_cart.rb @@ -1,4 +1,5 @@ require "shopping_cart/engine" +require 'haml' module ShoppingCart # Your code goes here... diff --git a/shopping_cart.gemspec b/shopping_cart.gemspec index 9c82462..8d442e4 100644 --- a/shopping_cart.gemspec +++ b/shopping_cart.gemspec @@ -17,6 +17,7 @@ Gem::Specification.new do |s| s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"] s.add_dependency "rails", "~> 5.0.0", ">= 5.0.0.1" - - s.add_development_dependency "pg" + s.add_dependency 'pg' + s.add_dependency 'aasm' + s.add_dependency 'haml' end diff --git a/spec/dummy/config/routes.rb b/spec/dummy/config/routes.rb index 24e4867..c0c3d10 100644 --- a/spec/dummy/config/routes.rb +++ b/spec/dummy/config/routes.rb @@ -1,3 +1,3 @@ Rails.application.routes.draw do - mount ShoppingCart::Engine => "/shopping_cart" + mount ShoppingCart::Engine => "/cart" end diff --git a/spec/dummy/db/schema.rb b/spec/dummy/db/schema.rb new file mode 100644 index 0000000..122a067 --- /dev/null +++ b/spec/dummy/db/schema.rb @@ -0,0 +1,74 @@ +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 20160820142403) do + + # These are extensions that must be enabled in order to support this database + enable_extension "plpgsql" + enable_extension "uuid-ossp" + + create_table "addresses", force: :cascade do |t| + t.string "address" + t.string "zipcode" + t.string "city" + t.string "phone" + t.string "first_name" + t.string "last_name" + t.string "country_code" + t.integer "order_id" + t.index ["order_id"], name: "index_addresses_on_order_id", using: :btree + end + + create_table "coupons", force: :cascade do |t| + t.string "code" + t.float "discount" + t.integer "order_id" + t.index ["order_id"], name: "index_coupons_on_order_id", using: :btree + end + + create_table "credit_cards", force: :cascade do |t| + t.string "number" + t.string "cvv" + t.integer "year" + t.integer "month" + t.string "firstname" + t.string "lastname" + end + + create_table "deliveries", force: :cascade do |t| + t.string "title" + t.float "price" + end + + create_table "order_items", force: :cascade do |t| + t.integer "quantity" + t.integer "order_id" + t.index ["order_id"], name: "index_order_items_on_order_id", using: :btree + end + + create_table "orders", force: :cascade do |t| + t.float "total" + t.string "state" + t.uuid "number", default: -> { "uuid_generate_v4()" } + t.integer "credit_card_id" + t.integer "delivery_id" + t.integer "user_id" + t.index ["credit_card_id"], name: "index_orders_on_credit_card_id", using: :btree + t.index ["delivery_id"], name: "index_orders_on_delivery_id", using: :btree + end + + add_foreign_key "addresses", "orders" + add_foreign_key "coupons", "orders" + add_foreign_key "order_items", "orders" + add_foreign_key "orders", "credit_cards" + add_foreign_key "orders", "deliveries" +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..47b39ce --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,103 @@ +# This file was generated by the `rspec --init` 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. +# +# The `.rspec` file also contains a few flags that are not defaults but that +# users commonly want. +# +# 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. +=begin + # 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! + + # This setting enables warnings. It's recommended, but in some cases may + # be too noisy due to issues in dependencies. + config.warnings = true + + # 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 +end