Tbpgr Blog

Organization Development Engineer tbpgr(てぃーびー) のブログ

RSpec | rspec helper | define helper method int module

概要

rspec helper | define helper method int module

詳細

Helperをmoduleで作成し、RSpec.configureに設定することで
複数のspec間で流用することができます。

lower.rb

module Lower
  def lower(text)
    text.downcase
  end
end

spec_helper.rb

require 'lower'
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
  config.include Lower
end

hige_spec.rb

require 'spec_helper'
require 'hige'

describe Hige do
  it "hige1" do
    expect("lower").to eq(lower("LOWER"))
  end
end

テスト結果

$ rspec
Run options: include {:focus=>true}

All examples were filtered out; ignoring {:focus=>true}
.

Finished in 0.001 seconds
1 example, 0 failures