LoginSignup
37

More than 5 years have passed since last update.

RSpec without Railsなspec_helper

Posted at

rspec-railsに頼りっきりで素RSpecの仕組みが理解不足だったためメモ。

最低限必要なrequireは以下の通り

  1. require 'rubygems' => 'bundler/setup'
  2. require 'rspec'
  3. require programs should be tested.
spec/spec_helper.rb
require "rubygems"
require "bundler/setup"
require 'rspec'
Dir[File.join(File.dirname(__FILE__), "..", "app", "**/*.rb")].each{|f| require f }

RSpec.configure do
  # ...
end
  • spec/というディレクトリ名はrspecが決め打ちしているため従った方が無難。
  • app/hoge/fuga.rbapp/nyarla/thotep.rbがある想定。
    • app/**/*.rb を一気にrequireしている

ここで設定したspec_helper.rbも別に自動に読み込まれるわけではなく、

spec/nyarla/thotep_spec.rb
require 'spec_helper'

としてやる必要がある。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
37