Skip to content

Instantly share code, notes, and snippets.

window.variableDefinedByGist = "foo!";
@yujinakayama
yujinakayama / package.json
Created June 24, 2022 05:34
.gcloudignore issue in google-github-actions/deploy-cloud-functions
{}
require 'fileutils'
NPM_2 = File.expand_path('./npm/2.15.2/package/bin/npm-cli.js')
NPM_3 = File.expand_path('./npm/3.8.5/package/bin/npm-cli.js')
describe 'npm', :vcr do
def run!(*command)
Kernel.system(*command) || raise("Command exited with status #{$?}")
end
@yujinakayama
yujinakayama / example.rb
Last active July 26, 2017 05:17
Example of switching positive/negative in compound expectations
describe 'some destructive method' do
it 'destroys only relevant things' do
expect { do_something_destructive }.to change { things_to_destroy.reload.count }.to(0)
.and.not_to change { things_not_to_destroy.reload.count }
# ^^^^^^^ This is what I want to do and just a fictional syntax.
end
end
@yujinakayama
yujinakayama / gemfile_version_specifier.rb
Created January 9, 2015 04:45
Automatic Gemfile version specifier
# Run `ruby gemfile_version_specifier.rb` in project root directory.
require 'astrolabe/builder'
require 'parser/current'
require 'bundler'
source_buffer = Parser::Source::Buffer.new('Gemfile')
source_buffer.read
builder = Astrolabe::Builder.new
@yujinakayama
yujinakayama / instance_eval_module_nesting.rb
Last active August 29, 2015 14:03
#instance_eval does not change the current namespace
module Foo
class Bar
BAZ = 'Hello'
def print_module_nesting
p Module.nesting
end
end
end
# coding: utf-8
require 'tmpdir'
require 'parser/current'
def in_tmpdir
Dir.mktmpdir do |tmpdir|
Dir.chdir(tmpdir) do
yield
end
@yujinakayama
yujinakayama / and_return_without_args_spec.rb
Last active August 29, 2015 13:56
The problematic behavior of `and_return` without arguments
describe '`and_return` without arguments' do
let(:obj) { double('obj') }
context 'with `stub`' do
context 'and `{ }` block' do
it 'works properly' do
obj.stub(:foo).and_return {
'a return value'
}