This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# spec/support/hit.rb | |
module HitSpec | |
def hit(*args, &block) | |
n = 100 | |
if args.last.is_a?(Hash) && args.last.key?(:n) | |
n = args.last.delete(:n) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it "doesn't make further requests when the cache is warm" do | |
stub = stub_request(:get, "www.amazon.com") | |
Amazon::API.new.item_prices("id") | |
Amazon::API.new.item_prices("id") | |
# https://github.com/bblimke/webmock#setting-expectations-in-rspec-on-the-stub | |
expect(stub).to have_been_requested.once | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
# app/models/concerns | |
module HasStringEnum | |
extend ActiveSupport::Concern | |
class_methods do | |
def string_enum(name, values, **options) | |
enum(name => values.zip(values).to_h, **options) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
class PgEnumMigrator | |
def initialize(migration:, table:, column:, enum_name:, mapping:, new_default: nil, old_default: nil) | |
@migration = migration | |
@table = table | |
@column = column | |
@enum_name = enum_name | |
@mapping = mapping | |
@new_default = new_default |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module TableSupport | |
def column_names(table_selector = "table") | |
find(table_selector).all("th").map(&:text) | |
end | |
def values_for_column(column_name, table_selector = "table") | |
table = find(table_selector) | |
index = table.all("th").map(&:text).find_index(column_name) | |
expect(index).to be_present, "Unable to find column named: #{column_name}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Make Bullet failing tests which opt-in to 'strict' mode | |
# | |
# Based on: | |
# https://github.com/flyerhzm/bullet#run-in-tests | |
# spec/rails_helper.rb or similar | |
RSpec.configure do |config| | |
config.before(:example, :ar_strict) do | |
Bullet.enable = true | |
Bullet.bullet_logger = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "bundler/inline" | |
gemfile do | |
gem "rspec" | |
end | |
require "rspec/autorun" | |
RSpec.describe "inline Bundler and autorun RSpec" do | |
it "is convenient for self-contained examples & bug repros" do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Checks test files are named "_spec.rb" to match the RSpec globs property | |
# defined in .circleci/config.yml. This will fail the build if there are test | |
# files which don't match the required pattern. | |
# Ignores first-level helper files (e.g. spec_helper.rb) and the spec/support, | |
# spec/factories, spec/shared_examples folders | |
set -eu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Save stdout & stderr to individual files: | |
bundle exec rspec > >(tee stdout.log) 2> >(tee stderr.log >&2) | |
# Calculate the percentage: | |
wc -l stderr.log stdout.log \ | |
| ruby -e \ | |
'err, _, total = ARGF.map(&:to_f); puts "#{(err/total*100).round}% error output"' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
**/* linguist-language=Go |
NewerOlder