Commit dbf5c8ab authored by the-undefined's avatar the-undefined

Move 'Search Snippets' Spinach feature to Rspec

This commit moves the `search_snippets.feature` Spinach test to a
Rspec feature, as part of deprecating the Spinach test suite.

- Remove Spinach discover snippets feature and steps
- Remove unused `SharedSearch` module
- Add Rspec feature scenarios
parent f27f9803
@dashboard
Feature: Snippet Search
Background:
Given I sign in as a user
And I have public "Personal snippet one" snippet
And I have private "Personal snippet private" snippet
And I have a public many lined snippet
Scenario: I should see my public and private snippets
When I search for "snippet" in snippet titles
Then I should see "Personal snippet one" in results
And I should see "Personal snippet private" in results
Scenario: I should see three surrounding lines on either side of a matching snippet line
When I search for "line seven" in snippet contents
Then I should see "line four" in results
And I should see "line seven" in results
And I should see "line ten" in results
And I should not see "line three" in results
And I should not see "line eleven" in results
module SharedSearch
include Spinach::DSL
def search_snippet_contents(query)
visit "/search?search=#{URI::encode(query)}&snippets=true&scope=snippet_blobs"
end
def search_snippet_titles(query)
visit "/search?search=#{URI::encode(query)}&snippets=true&scope=snippet_titles"
end
end
class Spinach::Features::SnippetSearch < Spinach::FeatureSteps
include SharedAuthentication
include SharedPaths
include SharedSnippet
include SharedUser
include SharedSearch
step 'I search for "snippet" in snippet titles' do
search_snippet_titles 'snippet'
end
step 'I search for "snippet private" in snippet titles' do
search_snippet_titles 'snippet private'
end
step 'I search for "line seven" in snippet contents' do
search_snippet_contents 'line seven'
end
step 'I should see "line seven" in results' do
expect(page).to have_content 'line seven'
end
step 'I should see "line four" in results' do
expect(page).to have_content 'line four'
end
step 'I should see "line ten" in results' do
expect(page).to have_content 'line ten'
end
step 'I should not see "line eleven" in results' do
expect(page).not_to have_content 'line eleven'
end
step 'I should not see "line three" in results' do
expect(page).not_to have_content 'line three'
end
step 'I should see "Personal snippet one" in results' do
expect(page).to have_content 'Personal snippet one'
end
step 'I should see "Personal snippet private" in results' do
expect(page).to have_content 'Personal snippet private'
end
step 'I should not see "Personal snippet one" in results' do
expect(page).not_to have_content 'Personal snippet one'
end
step 'I should not see "Personal snippet private" in results' do
expect(page).not_to have_content 'Personal snippet private'
end
end
require 'rails_helper'
feature 'Search Snippets', feature: true do
scenario 'User searches for snippets by title' do
public_snippet = create(:personal_snippet, :public, title: 'Beginning and Middle')
private_snippet = create(:personal_snippet, :private, title: 'Middle and End')
login_as private_snippet.author
visit dashboard_snippets_path
page.within '.search' do
fill_in 'search', with: 'Middle'
click_button 'Go'
end
click_link 'Titles and Filenames'
expect(page).to have_link(public_snippet.title)
expect(page).to have_link(private_snippet.title)
end
scenario 'User searches for snippet contents' do
create(:personal_snippet,
:public,
title: 'Many lined snippet',
content: <<-CONTENT.strip_heredoc
|line one
|line two
|line three
|line four
|line five
|line six
|line seven
|line eight
|line nine
|line ten
|line eleven
|line twelve
|line thirteen
|line fourteen
CONTENT
)
login_as create(:user)
visit dashboard_snippets_path
page.within '.search' do
fill_in 'search', with: 'line seven'
click_button 'Go'
end
expect(page).to have_content('line seven')
# 3 lines before the matched line should be visible
expect(page).to have_content('line six')
expect(page).to have_content('line five')
expect(page).to have_content('line four')
expect(page).not_to have_content('line three')
# 3 lines after the matched line should be visible
expect(page).to have_content('line eight')
expect(page).to have_content('line nine')
expect(page).to have_content('line ten')
expect(page).not_to have_content('line eleven')
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment