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 "length of Spock's and his friends' names"() { | |
expect: | |
name.size() == length | |
where: | |
name | length | |
"Spock" | 5 | |
"Kirk" | 4 | |
"Scotty" | 6 | |
} |
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 "length of Spock's and his friends' names"() { | |
assert "Spock".size() == 5 | |
assert "Kirk".size() == 3 | |
assert "Scotty".size() == 6 | |
} |
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 | |
validates_presence_of :name | |
has_many :addresses | |
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
class Person < Struct.new(:name, :age) | |
def to_s | |
"#{name} is #{age} years old" | |
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
# Framework | |
# =========================================== | |
module ContextAccessor | |
def context | |
Thread.current[:context] | |
end | |
end | |
module Context | |
include ContextAccessor |
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
# Framework | |
# =========================================== | |
module ContextAccessor | |
def context | |
Thread.current[:context] | |
end | |
end | |
module Context | |
include ContextAccessor |
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 Account | |
def decrease_balance(amount); end | |
def increase_balance(amount); end | |
def balance; end | |
def update_log(message, amount); end | |
def self.find(id); 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
class TransferringMoney | |
include Context | |
def self.transfer source_account_id, destination_account_id, amount | |
source = Account.find(source_account_id) | |
destination = Account.find(destination_account_id) | |
TransferringMoney.new(source, destination).transfer amount | |
end | |
attr_reader :source_account, :destination_account |
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 TransferringMoney | |
include Context | |
... | |
def transfer amount | |
... | |
end | |
module SourceAccount | |
include ContextAccssor |
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 TransferringMoney | |
include Context | |
def self.transfer source_account_id, destination_account_id, amount | |
source = Account.find(source_account_id) | |
destination = Account.find(destination_account_id) | |
TransferringMoney.new(source, destination).transfer amount | |
end | |
attr_reader :source_account, :destination_account |