Skip to content

Instantly share code, notes, and snippets.

@TAKAyukiatkwsk
Last active January 3, 2016 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TAKAyukiatkwsk/0d4121131b9eb153184e to your computer and use it in GitHub Desktop.
Save TAKAyukiatkwsk/0d4121131b9eb153184e to your computer and use it in GitHub Desktop.
空のプロジェクトで、Rspecをセットアップする
$ mkdir new_project & cd new_project
$ bundle init
#=> Gemfileのひな形が生成される
$ vim Gemfile
#=> gem "rspec" を追加する
$ bundle install --path vendor/bundle
$ bundle exec rspec --init
create spec/spec_helper.rb
create .rspec
$ tree .
.
├── Gemfile
├── Gemfile.lock
├── spec
│   └── spec_helper.rb
└── vendor
# ひな形ができたのでコードを書き始める
# 例えば...
$ mkdir lib
$ touch lib/hoge.rb
$ mkdir spec/lib
$ touch spec/lib/hoge_spec.rb
$ bundle exec rspec spec
class Hoge
def fuga
'hahaha'
end
end
require 'spec_helper'
describe Hoge do
describe "#fuga" do
it "returns 'hahaha'" do
expect(hoge.fuga).to eq("hahaha")
end
end
end
require 'rubygems'
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'hoge'))
# 以下は rspec --init で生成されるので、使うかどうかは好みでOKです。
# This file was generated by the `rspec --init` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# Require this file using `require "spec_helper"` to ensure that it is only
# loaded once.
#
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
config.run_all_when_everything_filtered = true
config.filter_run :focus
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = 'random'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment