Skip to content

Instantly share code, notes, and snippets.

module CoolMixin
extend ActiveSupport::Concern
included do
before(:each) do
# Whatever
end
after(:all) do
# Whatever
require 'spec_helper'
describe Api::V1_2::TokensController do
def parsed_response(response)
JSON.parse(response.body)
end
describe "POST create" do
let(:params) { {} }
@shepmaster
shepmaster / gist:5020689
Last active December 14, 2015 03:28
Nested subject accessing the parent?
describe Array do
describe "the return value" do
subject do
subject.size # This obviously causes infinite recursion :-)
end
end
end
describe Array do
subject(:array) { Array.new }
# require 'openssl'
class UserData #< OpenSSL::X509::Name
def to_a
[0,1,2]
end
alias _dump_data to_a
def _load_data entries
entries.each do |entry|
@shepmaster
shepmaster / vary-input-spec.rb
Created March 15, 2013 18:52
Show how to emphasize various parameters to an object (or function)
describe MyClass do
let(:size) { 10 } # An uninteresting size
let(:color) { "red" }
subject(:my_class) { MyClass.new(size, color) }
context "invalid sizes" do
context "negative sizes" do
let(:size) { -1 }
class Logwriter
SEVERITIES = [:info, :warning, :error, :critical]
# I wouldn't try to unit test this; integration test instead. It's
# also short enough I might just claim "it works".
def self.for_file(filename)
new(File.new(filename))
end
def initialize(io)
@io = io
class ContestEntry
end
class ContestEntriesController
def create(params)
@contest_entry = ContestEntry.new(params[:contest_entry])
@contest_entry.save
end
end
--- $LOAD_PATH:
/opt/wlp/1.0.1.cl0120121004_1949/wlp/usr/servers/staging/apps/cxo/WEB-INF/lib
/opt/wlp/1.0.1.cl0120121004_1949/wlp/usr/servers/staging/apps/cxo/WEB-INF/vendor
lib
/opt/wlp/1.0.1.cl0120121004_1949/wlp/usr/servers/staging/apps/cxo/WEB-INF/app/assets
/opt/wlp/1.0.1.cl0120121004_1949/wlp/usr/servers/staging/apps/cxo/WEB-INF/app/controllers
/opt/wlp/1.0.1.cl0120121004_1949/wlp/usr/servers/staging/apps/cxo/WEB-INF/app/helpers
/opt/wlp/1.0.1.cl0120121004_1949/wlp/usr/servers/staging/apps/cxo/WEB-INF/app/mailers
/opt/wlp/1.0.1.cl0120121004_1949/wlp/usr/servers/staging/apps/cxo/WEB-INF/app/models
/opt/wlp/1.0.1.cl0120121004_1949/wlp/usr/servers/staging/apps/cxo/WEB-INF/app/widgets
class Alpha
attr_reader :things
def initialize
@things = []
freeze
end
end
a = Alpha.new
class EasyAccess
include classpath.to.TrustStrategy
def isTrusted(chain, authType)
true
end
end