Last active
January 3, 2016 13:29
-
-
Save TAKAyukiatkwsk/0d4121131b9eb153184e to your computer and use it in GitHub Desktop.
空のプロジェクトで、Rspecをセットアップする
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
$ 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 |
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 Hoge | |
def fuga | |
'hahaha' | |
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
require 'spec_helper' | |
describe Hoge do | |
describe "#fuga" do | |
it "returns 'hahaha'" do | |
expect(hoge.fuga).to eq("hahaha") | |
end | |
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
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