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
require 'spec_helper' | |
shared_examples "valid" do | |
it { expect { subject }.not_to raise_error(Avalon::Error) } | |
end | |
shared_examples "invalid" do | |
it { expect { subject }.to raise_error(Avalon::Error) } | |
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
class Lens < Struct.new(:name, :mm, :f, :close_up, :generation) | |
def initialize(attrs) | |
super(*self.class.members.inject([]) {|r, x| r << attrs[x] }) | |
end | |
end | |
Lens.new( | |
f: 2, | |
generation: '3rd', |
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
context '入力が正しくない' do | |
[ | |
[:name, "未入力", nil, "can't be blank"], | |
[:name, "101文字以上", 'a' * 101, "is too long"], | |
[:display, "101文字以上", 'a' * 101, "is too long"] | |
] | |
.each do |attr, state, value, msg| | |
context "#{attr.to_s.humanize}が#{state}" do | |
let(:input) { valid_input.merge(attr => value) } |
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
before do | |
@resources = FactoryGirl.create_list(:resource, 10) | |
end | |
it 'それぞれのResourceが表示されていること' do | |
visit '/resources' | |
@resources.each do |r| | |
expect(page).to have_content(/#{r.id}\s+#{r.attr1}\s+#{r.attr2}\s+#{r.attr3}/) | |
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
sub group_by(&@) { | |
my $block = shift; | |
my %result; | |
for (@_) { | |
my $key = $block->($_); | |
$result{$key} = [] unless exists $result{$key}; | |
push @{ $result{$key} }, $_; | |
} |
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
#logs | |
@timeline = Timeline.find(current_user) | |
@timeline.each do |activity| | |
p activity.date | |
p activity.balance | |
p activity.outgo | |
p activity.income | |
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
uname -a |
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
package main | |
import "fmt" | |
// 料理を作るI/F | |
type Cooker interface { | |
Cook() string | |
} | |
// 塗るI/F |
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
class KaraokeMachine | |
def initialize(melody_string) | |
@melody = Melody.parse(melody_string) | |
end | |
def transpose(amount) | |
@melody.transpose(amount).present | |
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
package main | |
import "fmt" | |
// 料理を作るI/F | |
type Cooker interface { | |
Cook() string | |
} | |
// 塗るI/F |
OlderNewer