D
D
Diesel-nick2016-06-22 08:18:54
Ruby on Rails
Diesel-nick, 2016-06-22 08:18:54

RSpec Rails - why aren't all tests checked in features?

I'm trying to test a Rails application through RSpec using the syntax recommended on these resources:
https://relishapp.com/rspec/rspec-rails/v/3-2/docs...
betterspecs.org/en
Wrote this spec for testing main pages:
spec/features/main_pages_spec.rb

require 'rails_helper'

RSpec.describe "main pages", type: :features do

  scenario "root page" do
    visit root_path

    expect(page).to have_link("Login", href: login_path(locale: I18n.locale))
    expect(page).to have_link("Signup", href: signup_path(locale: I18n.locale))
  end
end

But at startup only the first expect is tested
bundle exec rspec spec/features/main_pages_spec.rb
Run options: include {:focus=>true}

All examples were filtered out; ignoring {:focus=>true}

Randomized with seed 47521

main pages
  root page

Top 1 slowest examples (1.4 seconds, 99.9% of total time):
  main pages root page
    1.4 seconds ./spec/features/main_pages_spec.rb:8

Finished in 1.4 seconds (files took 4.58 seconds to load)
1 example, 0 failures

These are my application gems
gem 'rails', '~> 4.2', '>= 4.2.5'
gem 'rspec-rails', '~> 3.3'
gem 'capybara', '~> 2.5'
gem 'minitest'
gem 'selenium-webdriver', '~> 2.48'

Why is only the first expect being tested?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Sidorov, 2016-06-22
@Diesel-nick

Both expect pass. In feature tests, scenario is synonymous with it from regular tests.
If rspec logs that the test has passed, then everything that is written in it has been completed.
To verify this, try the following code

scenario "root page" do
  visit root_path

  puts 'A'
  expect(page).to have_link("Login", href: login_path(locale: I18n.locale))
  puts 'B'
  expect(page).to have_link("Signup", href: signup_path(locale: I18n.locale))
  puts 'C'
end

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question