Forum: RSpec Global before block for specific spec type

Posted by Evgeniy Dolzhenko (dolzenko)
on 2010-08-31 20:46
(Received via mailing list)
So previously it seems it was possible to configure global before block 
which
will get run, say only for controller specs (people even used that I
think 
http://stackoverflow.com/questions/590100/setting-the-http-referer-in-a-global-beforeall-in-rspec/592219#592219
)

Now I wasn't able to find anything like that, and the closest thing I
came up with
is:

RSpec.configure do |config|
  config.before(:all) do
    if self.class.metadata[:type] == :view
      # do my dirty deeds with ViewExampleGroup
    end
  end
end

Is that OK?
Posted by David Chelimsky (Guest)
on 2010-08-31 20:48
(Received via mailing list)
On Aug 31, 2010, at 1:45 PM, Evgeniy Dolzhenko wrote:

>  config.before(:all) do
>    if self.class.metadata[:type] == :view
>      # do my dirty deeds with ViewExampleGroup
>    end
>  end
> end
> 
> Is that OK?

Better to do this:

RSpec.configure do |config|
  config.before(:all, :type => :view) do
    # do stuff
  end
end
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.