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
$ bundle exec ruby spec.rb 1 ↵ | |
Fetching gem metadata from https://rubygems.org/.......... | |
Resolving dependencies... | |
Using bundler 1.17.3 | |
Using diff-lcs 1.3 | |
Using rspec-support 3.8.0 | |
Using rspec-core 3.8.0 | |
Using rspec-expectations 3.8.2 | |
Using rspec-mocks 3.8.0 |
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
# app/controllers/owner/reservations_controller.rb | |
class Owner::ReservationsController < ApplicationController | |
def create | |
# … | |
end | |
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
# a.rb | |
require_relative 'a/b' | |
module A | |
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
# lib/sidekiq/middleware/server/retry_jobs_without_exception.rb | |
module Sidekiq | |
RetryWithoutException = Class.new(StandardError) | |
module Middleware | |
module Server | |
class RetryJobsWithoutException < RetryJobs | |
def call(worker, msg, queue) | |
begin |
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
class SomeModel < ApplicationRecord | |
after_initialize do | |
if new_record? | |
{some_attribute: 'default value'}.each do |attribute, value| | |
public_send("#{attribute}=", value) unless public_send(attribute) | |
end | |
end | |
end | |
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 | |
require "action_dispatch/testing/request_encoder" | |
module ActionDispatch | |
# Integration test methods such as ActionDispatch::Integration::Session#get | |
# and ActionDispatch::Integration::Session#post return objects of class | |
# TestResponse, which represent the HTTP response results of the requested | |
# controller actions. | |
# |
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
class BaseAuditsController < ApplicationController | |
def self.inherited(other) | |
other.class_eval do | |
resource_name = controller_path.split('/').first.singularize | |
define_method("set_#{resource_name}") do | |
resource = organization.public_send(resource_name.pluralize).find(params["#{resource_name}_id"]) | |
instance_variable_set("@#{resource_name}", resource) | |
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
Listen.to('app/controllers') do |modified, added, removed| | |
puts "modified absolute path: #{modified}" | |
puts "added absolute path: #{added}" | |
puts "removed absolute path: #{removed}" | |
end.start |
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
'foo' + 42 # => TypeError: no implicit conversion of Integer into String | |
class Integer | |
def to_str | |
to_s | |
end | |
end | |
'foo' + 42 # => 'foo42' |
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
class A | |
def self.foo | |
end | |
end | |
class B < A | |
end | |
mock_a = MiniTest::Mock.new | |
mock_b = MiniTest::Mock.new |