izumin5210/rspec-cheki

impossible to use in shared context - specify snapshots path

Opened this issue · 0 comments

shared context

shared_context 'template_snapshot' do
  let(:description) { self.class.description }

  it 'matches' do
    expect(JSON.generate(payload)).to match_snapshot
  end
end

usage

  describe 'bar' do
    include_context 'template_snapshot'
    let(:payload) { { foo: bar } }
  end

  describe 'baz' do
    include_context 'template_snapshot'
    let(:payload) { { foo: :baz } }
  end

Problem :

It won't work since there's only one snapshot created under the shared context path

Solution :

let us choose the path of the snapshot like https://github.com/yesmeck/rspec-snapshot for example

shared_context 'template_snapshot' do
  let(:description) { self.class.description }

  it 'matches' do
    expect(JSON.generate(payload)).to match_snapshot("path/to/snapshosts/#{description}"
  end
end