View gist:2528600
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
case some_value | |
when 1..10 | |
"do some stuff here" | |
when 11..20 | |
"do something else here" | |
else | |
"out of range" | |
end | |
# compared to |
View wrap.rb
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 Wrap < Struct.new(:string, :max_length) | |
def self.wrap(s, max_length) | |
raise ArgumentError.new("Maximum wrap length can't be 0") if max_length == 0 | |
new(s, max_length).wrap | |
end | |
def wrap | |
return [""] if blank? | |
string.scan(regexp) | |
end |
View whale_test.rb
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 'test/unit' | |
class Whale | |
def self.attr_validated(method_name, &validation) | |
# Enter code here to make all tests pass. | |
end | |
attr_validated :num_teeth do |v| | |
v <= 4 | |
end |
View beget.js
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
function beget(parent, child){ | |
// put code here to make test() return true | |
}; | |
function test(){ | |
function Parent(){ | |
throw 'exception'; | |
}; | |
Parent.prototype = {code: Math.random()}; |
View spec_example.rb
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('uses the client time zone') do | |
allow(described_class).to receive(:delete_cache) do | |
fail unless Time.zone == client_time_zone | |
end | |
allow(described_class).to receive(:create_cache) do | |
fail unless Time.zone == client_time_zone | |
end | |
update_for_year | |
end |
View buckets_controller_spec.rb
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 'spec_helper' | |
describe BucketsController do | |
render_views | |
login_admin | |
def valid_attributes | |
FactoryGirl.attributes_for(:bucket) | |
end |
View original.rb
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
describe Sweeper do | |
context 'a subscription is expired' do | |
let(:bob) { double(active?: true, paid_at: 2.months.ago) } | |
let(:users) { [bob] } | |
before { allow(User).to receive(:all).and_return(users) } | |
it 'emails the user' do | |
expect(UserMailer).to receive(:billing_problem).with(bob) | |
described_class.sweep | |
end |
View results.txt
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
expected collection contained: [#<User id: 1, email: "user1@example.com", ...a bunch of attributes...>] | |
actual collection contained: [#<User id: 1, email: "user1@example.com", ...a bunch of attributes...>, | |
#<User id: 2, email: "user2@example.com", ...a bunch of attributes...>] |
View names_for_let_object.rb
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 NamesForLetObject | |
def names_for_let_objects(objects) | |
objects.map { |object| name_for_let_object(object) } | |
end | |
def name_for_let_object(object) | |
__memoized.instance_variable_get(:@memoized).key(object) | |
end | |
end |
View a_foreign_key_constraint_association.rb
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
RSpec.shared_examples('a foreign_key constraint association') do | |
specify do | |
expect do | |
build(described_model, "#{association}_id" => 0).save(validate: false) | |
end.to raise_error(ActiveRecord::InvalidForeignKey) | |
end | |
end |
OlderNewer