Skip to content

Instantly share code, notes, and snippets.

Eumir Gaspar corroded

View GitHub Profile
View thing_spec_revisited.rb
subject(:valid_things_ids) { described_class.valid_things_ids(group) }
let(:group) { 'blurb' }
let!(:random_thing) { FactoryGirl.create(:something, group: 'blurb', id: 111) }
let!(:another_thing) { FactoryGirl.create(:something, group: 'blurb', id: 222) }
let!(:not_included) { FactoryGirl.create(:something, group: 'shrug', id: 333) }
it do
expect(valid_things_ids).to include 111
View thing_spec.rb
subject(:valid_things_ids) { described_class.valid_things_ids(group) }
let(:group) { 'example' }
before do
described_class::VALID_THINGS.each do |thing|
FactoryGirl.create(:something, group: 'example', name: thing)
end
end
@corroded
corroded / spec.rb
Created Apr 7, 2018
Covetous example
View spec.rb
describe 'when receiving the hero details' do
it 'should have the top level keys as methods' do
top_level_keys = %w{id name gender level paragonLevel hardcore skills items followers stats kills progress dead last-updated}
top_level_keys.each do |tl_key|
@my_hero.send(tl_key).must_equal @my_hero.response[tl_key.camelize(:lower)]
end
end
end
@corroded
corroded / car_crasher.rb
Created Mar 9, 2018
An initial example of the car crasher service object
View car_crasher.rb
# frozen_string_literal: true
module Vehicle
class Crasher
def initialize(vehicle)
@vehicle = vehicle
end
def run
return if vehicle.parked? || vehicle.stalled?
View routeBuilder.js
'use strict'
const config = require('config')
module.exports.myUrl = (uploader, method) => {
return `http://example.com/${uploader}/${method}`
}
View api_caller_spec.rb
RSpec.describe ApiCaller do
describe '#run' do
let(:route_builder_mock) { instance_double(RouteBuilder }
before do
allow(RouteBuilder).to receive(:new).and_return(route_builder_mock)
end
context 'route builder threw an error' do
before do
View api_caller.rb
require 'rest-client'
class ApiCaller
def run
url = RouteBuilder.new(some_arg: 'hello').run
RestClient.post(url, params, headers)
end
end
@corroded
corroded / original_spec.rb
Created Feb 26, 2018
Sample Rspec to convert to JS
View original_spec.rb
context 'street name is also a street type' do
let(:street) { 'Gap Road' }
let(:expected_hash) { { street_name: 'Gap', street_type: 'Road' } }
it { is_expected.to eq expected_hash }
end
@corroded
corroded / expected.spec.js
Last active Feb 26, 2018
Sample Rspec to JS
View expected.spec.js
describe('street name is also a street type (Gap Road)', () => {
it('splits the street name/type properly', () => {
const result = streetTypeExtractor('Gap Road')
const expectedObject = {
streetName: 'Gap',
streetType: 'Road',
}
expect(result).to.deep.eq(expectedObject)
})
View fibonacci.rb
require 'benchmark'
def it_fibonacci(n)
fib_arr = [0,1]
(2..(n.to_i) - 1).each do |x|
fib_arr << fib_arr[x-1] + fib_arr[x-2]
end
return fib_arr
end
You can’t perform that action at this time.