This file contains hidden or 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 ActiveLinkToDefaults | |
def active_link_to(name, options, html_options = {}) | |
html_options[:wrap_tag] = 'li' | |
super(name, options, html_options) | |
end | |
end | |
ActionView::Base.send :include, ActiveLinkToDefaults |
This file contains hidden or 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
def it description = "", metadata = {}, &block | |
if metadata && !metadata.empty? # perhaphs just `if !metadata.empty?` will suffice? | |
# your code | |
else | |
old_it description, &block | |
end | |
end |
This file contains hidden or 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 'active_attr' | |
class Address | |
include ActiveAttr::Model | |
attribute :city | |
attribute :country | |
validates :city, presence: true | |
validates :city, inclusion: { in: ["Vatican"] }, if: lambda { |address| address.country == 'Vatican' } |
This file contains hidden or 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 'minitest/autorun' | |
module MiniTest::Assertions | |
def assert_changes(obj, method, exp_diff) | |
before = obj.send method | |
yield | |
after = obj.send method | |
diff = after - before | |
assert_equal exp_diff, diff, "Expected #{obj.class.name}##{method} to change by #{exp_diff}, changed by #{diff}" |
This file contains hidden or 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 Address | |
include ActiveModel::ValueObject | |
attribute :street | |
attribute :city | |
end | |
class User < ActiveRecord::Base | |
attr_accessible :address | |
serialize :address, Address |
This file contains hidden or 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 'minitest/autorun' | |
class SetTest < MiniTest::Unit::TestCase | |
def setup | |
@set = Set.new | |
end | |
def test_size | |
assert_equal 0, @set.size | |
@set.add 42 |
This file contains hidden or 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 'minitest/autorun' | |
class SetTest < MiniTest::Spec | |
before do | |
@set = Set.new | |
end | |
specify '#size' do | |
@set.size.must_equal 0 | |
@set.add 42 |
This file contains hidden or 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 UsersController do | |
describe '#show' do | |
before { get :show, id: user.id } | |
it { should respond_with :success } | |
it { should assign_to(:user).with(user) } | |
context 'with public user' do | |
let(:user) { Factory(:public_user) } | |
end |
This file contains hidden or 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
namespace :test do | |
Rake::TestTask.new(:all) do |t| | |
t.libs << 'test' | |
t.pattern = 'test/**/*_test.rb' | |
end | |
end | |
task default: 'test:all' |
This file contains hidden or 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 MiniTest::Spec | |
def self.context(desc, &block) | |
stack = MiniTest::Spec.describe_stack | |
name = [stack.last, desc].compact.join('::') | |
Class.new self do | |
@name = name | |
class_eval &block | |
end | |
end |