New to Ruby and RSpec so please be gentle.
I'm from the Python world, pytest specifically. One of the things that you can do in pytest is use fixtures in your test and in other fixtures. In an ultra simple example, let's say we have a create fixture, and a delete fixture that requires create. If we had a test that uses both the create and delete fixtures, create would only be called once (even though delete uses create, pytest knows it's already been called for the test case. Here's some sample python code:
# test_fixture_reuse.py
import pytest
@pytest.fixture
def create_something():
"""Create tester object"""
#return MyTester(request.param)
print ("created_something")
@pytest.fixture
def delete_something(create_something):
"""Create tester object"""
#return MyTester(request.param)
print ("delete_something")
class TestIt:
def test_only_create(self, create_something):
print ("in test_only_create")
assert 1
def test_create_and_delete(self, create_something, delete_something):
print ("in test_create_and_delete")
assert 1
def test_only_delete(self, delete_something):
print ("in test_only_delete")
assert 1
Running pytest -v test_fixture_reuse -s returns this output, as expected:
test_parameterized_fixture.py::TestIt::test_only_create created_something
in test_only_create
PASSED
test_parameterized_fixture.py::TestIt::test_create_and_delete created_something
delete_something
in test_create_and_delete
PASSED
test_parameterized_fixture.py::TestIt::test_only_delete created_something
delete_something
in test_only_delete
PASSED
From what I've tried in Ruby, there is no equivalent concept to fixture and this means that each test needs to control the flow of calls. So if we're testing delete, the test would need to call create, and then call delete, but delete would have no explicit dependency on create. Fixtures in RSpec generally seem to map to models, so most of the search results are not relevant.
My question is - how can I do something similar to the python code above in RSpec? Or is this one of those things where I'm too boxed in of my view because of Python experience, and there's an analogous way of doing things in RSpec that I'm not searching for correctly?