Skip to content

Instantly share code, notes, and snippets.

View JunichiIto's full-sized avatar

Junichi Ito JunichiIto

View GitHub Profile
@JunichiIto
JunichiIto / bingo_spec.rb
Created March 5, 2015 08:16
ビンゴカード作成問題・解答テンプレート (https://codeiq.jp/ace/ito_junichi/q1326)
# coding: utf-8
class Bingo
def self.generate_card
# 以下の行は削除して、自分でロジックを実装してください。
sample
end
def self.sample
<<-CARD
require 'minitest/autorun'
module SumMatrix
extend self
def generate_sum_matrix(col: 4, row: 4, number_range: 1..1000)
matrix = generate_matrix(col: col, row: row, number_range: number_range)
format_matrix(sum_matrix(matrix))
end
require 'test/unit'
require 'csv'
class FillBlankTest < Test::Unit::TestCase
def fill_blank(csv_text)
CSV.parse(csv_text).inject([]) { |results, row|
results << row.zip(results.last || []).map { |curr, prev| curr || prev }
}
.map { |row| row.join(',') }
.join("\n")
describe 'Test true/truthy' do
context 'test 1' do
example do
expect(1).to be_truthy
end
example do
expect(1).to be true
end
example do
expect(1).to eq true
@JunichiIto
JunichiIto / rails_helper.rb
Created June 22, 2015 09:34
Sample DatabaseCleaner setting
# gem 'database_cleaner', '~> 1.4'
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
require 'spec_helper'
class Foo
def self.bar(*args)
raise 'Should be stubbed.'
end
end
describe 'Large args' do
example do
require 'spec_helper'
class Foo
def self.bar(*args)
puts "foo"
"bar"
end
end
describe Foo do
# see also
# https://relishapp.com/rspec/rspec-mocks/v/3-9/docs/configuring-responses/block-implementation#simulating-a-transient-network-failure
describe 'Mock' do
specify do
foo = double
counter = 0
allow(foo).to receive(:bar) do
if counter.zero?
counter += 1
'abc'
require 'rspec'
class Person
def hello(name)
puts "Hello, #{name}"
end
end
describe do
example do
describe 'test' do
example do
x = [{id: 1, name: 'hoge'}, {id: 2, name: 'fuga'}]
expect(x).to a_collection_including a_hash_including(id: 2), a_hash_including(id: 1)
end
end