[feature specs] Use before and after hooks

23 views
Skip to first unread message

Javix

unread,
Jun 4, 2014, 9:38:03 AM6/4/14
to rs...@googlegroups.com
How is it possible to use before and after hooks in feature specs just for one of scenarios only ?
I tried to use one as follows:

feature "Operations page" do

... some scenarios are omitted...

    scenario "List all operations with pagination" do
      before(:all) do
      31.times do
        create(:deposit,
            value_date: Date.today,
            sum: 1000,
            rate: 2.5,
            withholding: 12,
            close_date: Date.today + 3.months)
      end
    end

    expect(page).to have_selector('div.pagination')     

   end
and getting the error:

Failure/Error: before(:all) do
NoMethodError:
  undefined method `before' for #<RSpec::Core::ExampleGroup::Nested_1:0x5a3b328>

It's OK to use 'background' but it will be executed before each of the feature scenarios if I'm not mistaken. Right ?

I'm using RSpec 2.14.2
Ruby 2.0.0p353
Rails 4.0.3

Thank you.

Ester Ytterbrink

unread,
Dec 12, 2014, 8:03:13 AM12/12/14
to rs...@googlegroups.com
Hi!
Have you tried to put the scenario in a context?
like 
feature 'My feature ' do
context '31 deposits' do
  before(:all) do
    #your before all
  end
  scenario 'scenario 1 that use 31 deposits' do
    expect()
  end
  
  scenario 'scenario 2 that use 31 deposits' do
    expect()
  end
end
end

/Ester

On Wednesday, June 4, 2014 3:38:03 PM UTC+2, Javix wrote:
How is it possible to use before and after hooks in feature specs just for one of scenarios only ?
I tried to use one as follows:

feature "Operations page" do

... some scenarios are omitted...

    scenario "List all operations with pagination" do
      before(:all) doHi!
Reply all
Reply to author
Forward
0 new messages