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 User | |
| has_one :character | |
| end | |
| class Character | |
| belongs_to :user | |
| has_many :battles | |
| has_many :battle_records | |
| 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
| Rack::Utils::SYMBOL_TO_STATUS_CODE.each do |symbol,code| | |
| matcher_name = symbol.to_s =~ /^not_/ ? symbol : "be_#{symbol}" | |
| RSpec::Matchers.define matcher_name do | |
| match do |response| | |
| response.code.to_i == code |
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 Fixnum do | |
| subject { [1,2,3,4] } | |
| specify { subject.all?{|v| v==1} } | |
| it { should_not be_all{|v| v==1 }} | |
| it { should be_any{|v| v==1 } } | |
| it { should be_any(&lambda{|v| v==1 }) } | |
| end | |
| class Foo |
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
| # lambda/proc ver | |
| class Proc | |
| def self.compose(f, g) | |
| lambda {|*args| f[g[*args]] } | |
| end | |
| def <<(g) | |
| Proc.compose(self,g) | |
| 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 Foo | |
| def self.show | |
| 'foo' | |
| end | |
| class << self | |
| def show_with_bar | |
| "#{show_without_bar} bar" | |
| end | |
| alias :show_without_bar :show |
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
| #!/usr/bin/env ruby | |
| # -*- coding: utf-8 -*- | |
| class Foo | |
| def self.show | |
| 'foo' | |
| end | |
| end | |
| module Bar |
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
| user nginx nginx; | |
| worker_processes 1; | |
| error_log /var/log/nginx/error_log info; | |
| events { | |
| worker_connections 1024; | |
| use epoll; | |
| } |
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 'net/http' | |
| uri = URI.parse('http://[::1]:3000') | |
| puts uri.host #=> '[::1]' | |
| puts uri.hostname #=> '::1' | |
| Net::HTTP.start(uri.host, uri.port) do |http| | |
| http.get('/') | |
| end #=> getaddrinfo: Name or 2 vice not known (SocketError) |
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 'date' | |
| describe Date do | |
| it do | |
| Date.stub(:today) { 'today' } | |
| Date.today.should == 'today' | |
| 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 FizzBuzz | |
| def self.say(num) | |
| str = [[:Fizz][num%3], [:Buzz][num%5]].join('') | |
| str.empty? ? num : str | |
| end | |
| end | |
| describe FizzBuzz do | |
| subject { described_class.say(num) } | |
| context 'with 1' do |