On Fri, Aug 21, 2015, at 10:34 PM, [email protected] wrote:
> 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?
I'm guessing `host!` is provided by rspec-rails, in which case it's only
available to specs tagged as a rails controller (and not to suite)

Since this is a cheap operation, I'd be inclined to do it in a
before(:each) block. That way even if another test changes it will still
behave correctly.

>
> *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?
By default rspec-rails applies a feature called "transactional
fixtures", that wraps each spec in a transaction. This *does not*
include before(:all) hooks, which explains what you're seeing. I don't
recommend using `before(:all)` for database related things.
`before(:each)` should be fine.

I know that's not the most satisfying answer, but hopefully it helps.

Cheers, Xavier

>
> gem versions: rspec (2.99.0) rspec-rails (3.0.2) rspec-core (3.0.4,
> 2.99.2) rails (4.1.1)
>
>


> --
>
You received this message because you are subscribed to the Google
Groups "rspec" group.
>
To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected].
>
To post to this group, send email to [email protected].
>
To view this discussion on the web visit
https://groups.google.com/d/msgid/rspec/6a03880f-f3aa-469c-b8af-e053bb1b2b40%40googlegroups.com[1].
>
For more options, visit https://groups.google.com/d/optout.



Links:

  1. 
https://groups.google.com/d/msgid/rspec/6a03880f-f3aa-469c-b8af-e053bb1b2b40%40googlegroups.com?utm_medium=email&utm_source=footer

-- 
You received this message because you are subscribed to the Google Groups 
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rspec/1440209067.3512328.362804425.57C09D43%40webmail.messagingengine.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to