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
| # RSpec matcher to spec delegations. | |
| # | |
| # Usage: | |
| # | |
| # describe Post do | |
| # it { should delegate(:name).to(:author).with_prefix } # post.author_name | |
| # it { should delegate(:month).to(:created_at) } | |
| # it { should delegate(:year).to(:created_at) } | |
| # 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
| # RSpec matcher to spec serialized ActiveRecord attributes. | |
| # | |
| # Usage: | |
| # | |
| # describe Post do | |
| # it { should serialize(:data) } # serialize :data | |
| # it { should serialize(:registers).as(Array) } # serialize :registers, Array | |
| # it { should serialize(:options).as(Hash) } # serialize :options, Hash | |
| # 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
| module RSpec | |
| module Mocks | |
| module BulkDoubles | |
| module ClassMethods | |
| # Declares a bunch of test doubles at once. | |
| # | |
| # +name+ will be both the name of the double and the method name used | |
| # to invoke it. | |
| # |
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
| # See Mike Perham's proposal on ticket: https://rails.lighthouseapp.com/projects/8994/tickets/6477-activemodel-transformations | |
| module ActiveModel | |
| # == Active Model Transformations | |
| # | |
| # Provides a set of callbacks to perform transformations on your model | |
| # attributes before being assigned. | |
| # | |
| # A minimal implementation could be: |
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
| $ gem install minitest rspec | |
| $ time ruby rspec.rb && time ruby minispec.rb && time ruby minitest.rb | |
| ................ | |
| Finished in 0.01554 seconds | |
| 16 examples, 0 failures | |
| ruby rspec.rb 0.21s user 0.08s system 99% cpu 0.290 total | |
| ------------------------------- |
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
| --- | |
| BUNDLE_DISABLE_SHARED_GEMS: "1" |
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 Person | |
| # @count is a CLASS INSTANCE VARIABLE exclusive to Person. | |
| # Only when you instantiate a Person (not a subclass of Person), | |
| # the count increases. | |
| @count = 0 | |
| def initialize | |
| self.class.count += 1 | |
| 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
| # local 0 is an array | |
| # local 1 is a pointer which serves as an index of that array | |
| # Check the contents of the new cell | |
| g.push_local 0 | |
| g.push_local 1 | |
| g.send :[], 1, false | |
| fin = g.new_label | |
| g.git fin |
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
| # This stage takes a tree of Brainfuck::AST nodes and | |
| # simply calls the bytecode method on them. | |
| class Generator < Rubinius::Compiler::Stage | |
| next_stage Rubinius::Compiler::Encoder | |
| attr_accessor :variable_scope, :root | |
| def initialize(compiler, last) | |
| super | |
| @compiler = compiler | |
| @variable_scope = nil |
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 SomeLanguage | |
| module AST | |
| class SomeNode | |
| def bytecode(g) | |
| g.push_local 1 | |
| g.meta_push_1 | |
| g.meta_send_op_plus 0 | |
| g.set_local 1 | |
| # Check the contents of the new cell |