Home Rspec: Save record after previous tests
Reply: 1

Rspec: Save record after previous tests

tbard
1#
tbard Published in 2018-02-13 17:06:26Z

I want to run tests dynamically, using the loop. What I have:

let!(:product) { create(:product) }
let!(:data) { product.some_data_object }
let(:run_action) { patch :next_status, params: { id: data.id } }

STATUSES.each_with_index do |status, index|
  it "changes status from #{status} to #{STATUSES[index + 1]}" do
   run_action
   expect { data.reload }
     .to change { data.status }
       .from(status)
         .to(STATUSES[index + 1])
     end
  end
end

Each test should check if data.status is changed by one step from the array. But before each test data.status has the first value from the array.

So how can I get the old record with all changes after the previous test? Thank you.

Sharagoz
2#
Sharagoz Reply to 2018-02-13 19:16:42Z

Trying to persist data between tests is gonna lead to a lot of issues. You're better off running it all within one test:

it "should change status to the next one" do
  STATUSES.each_with_index do |status, index|
   patch :next_status, params: { id: data.id }
   expect { data.reload }
     .to change { data.status }
       .from(status)
         .to(STATUSES[index + 1])
  end
end
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.308812 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO