Hello everybody.
I'm confused with the
behaviour of before hooks and I have several questions:
1. The term :suite is supposed to run the hook once before the first spec runs. I need to set the host for the bunch of my request tests:
RSpec.configure do |config|
config.before(:suite) do
host! "foo.example.com"
end
end This raises undefined method host! error, however this works ok if I change :suite with :all Why? What is the correct way to once set the host for all the tests?
2. Resources, created in before(:each) block, are deleted automatically after tests:
RSpec.describe "Projects", :type => :request do
describe "GET /projects" do
context "common case" do
before do
@project = create(:project) # factory
get projects_path, nil, {Accept: 'application/json'}
end
it "should return status ok" do
....
....
end
end
end
However, if I change before with before(:all) (no need to create the resource again / make request again in my case), record stays in database. Why?
gem versions:
rspec (2.99.0)
rspec-rails (3.0.2)
rspec-core (3.0.4, 2.99.2)
rails (4.1.1)