0
votes

I have a head scratcher. When upgrading rspec I am getting:

DEPRECATION: let declaration `directory` accessed in an `after(:all)` hook 
at:
`let` and `subject` declarations are not intended to be called

Now I understand that I cannot use let defined variables in before/after hooks. However, the methods that are used with my test suite uses a connection to preform some REST API action:

let {:connection}   {user_base}
after(:all) do
 connection.delete_folder
end

My question is this: Is there anyway of getting around this without making every connection an instance variable? I want to avoid calling connection variable each time I want to preform an action e.g.

before(:all) do
 @connection = user_base
end
it "adds folder" do    
 @connection.add_folder
end
it "edits folder" do
 @connection.edit_folder
end
1

1 Answers

1
votes

I think RSpec wants you to run the block before each example instead of your once before all examples:

let(:connection) { user_base }

after do # short for `after(:each) do`
  connection.delete_folder
end

it "adds folder" do    
  connection.add_folder
end

it "edits folder" do
  connection.edit_folder
end