-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
107 additions
and
17 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require "spec_helper" | ||
|
||
describe Mobility::Attributes do | ||
describe "initializing" do | ||
specify { | ||
expect { described_class.new(:accessor, backend: :null) }.to allocate_under(9).objects | ||
} | ||
end | ||
|
||
describe "including into a class" do | ||
specify { | ||
klass = Class.new do | ||
include Mobility | ||
end | ||
attributes = described_class.new(:accessor, backend: :null) | ||
expect { klass.include attributes }.to allocate_under(30).objects | ||
} | ||
end | ||
|
||
describe "accessors" do | ||
let(:klass) do | ||
Class.new do | ||
include Mobility | ||
translates :title, backend: :null | ||
end | ||
end | ||
|
||
describe "calling attribute getter" do | ||
specify { | ||
instance = klass.new | ||
expect { 3.times { instance.title } }.to allocate_under(5).objects | ||
} | ||
end | ||
|
||
describe "calling attribute setter" do | ||
specify { | ||
instance = klass.new | ||
title = "foo" | ||
expect { 3.times { instance.title = title } }.to allocate_under(5).objects | ||
} | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require "spec_helper" | ||
|
||
describe Mobility::Configuration do | ||
context "when initializing" do | ||
specify { | ||
expect { described_class.new }.to allocate_under(7).objects | ||
} | ||
end | ||
end |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# borrowed from: https://blog.honeybadger.io/testing-object-allocations/ | ||
begin | ||
require 'allocation_stats' | ||
rescue LoadError | ||
puts 'Skipping AllocationStats.' | ||
end | ||
|
||
RSpec::Matchers.define :allocate_under do |expected| | ||
match do |actual| | ||
return skip('AllocationStats is not available: skipping.') unless defined?(AllocationStats) | ||
@trace = actual.is_a?(Proc) ? AllocationStats.new(burn: 1).trace(&actual) : actual | ||
@trace.new_allocations.size < expected | ||
end | ||
|
||
def objects | ||
self | ||
end | ||
|
||
def supports_block_expectations? | ||
true | ||
end | ||
|
||
def output_trace_info(trace) | ||
trace.allocations(alias_paths: true).group_by(:sourcefile, :sourceline, :class).to_text | ||
end | ||
|
||
failure_message do |actual| | ||
"expected under #{ expected } objects to be allocated; got #{ @trace.new_allocations.size }:\n\n" << output_trace_info(@trace) | ||
end | ||
|
||
description do | ||
"allocates under #{ expected } objects" | ||
end | ||
end |