bdd: Add tests for :edit-url
This commit is contained in:
parent
c4878bb7ed
commit
86dec02fe8
72
tests/integration/features/editor.feature
Normal file
72
tests/integration/features/editor.feature
Normal file
@ -0,0 +1,72 @@
|
||||
Feature: Opening external editors
|
||||
|
||||
## :edit-url
|
||||
|
||||
Scenario: Editing an URL
|
||||
When I open data/numbers/1.txt
|
||||
And I set up a fake editor replacing "1.txt" by "2.txt"
|
||||
And I run :edit-url
|
||||
Then data/numbers/2.txt should be loaded
|
||||
|
||||
Scenario: Editing an URL with -t
|
||||
When I run :tab-only
|
||||
And I open data/numbers/1.txt
|
||||
And I set up a fake editor replacing "1.txt" by "2.txt"
|
||||
And I run :edit-url -t
|
||||
Then data/numbers/2.txt should be loaded
|
||||
And the following tabs should be open:
|
||||
- data/numbers/1.txt
|
||||
- data/numbers/2.txt (active)
|
||||
|
||||
Scenario: Editing an URL with -b
|
||||
When I run :tab-only
|
||||
And I open data/numbers/1.txt
|
||||
And I set up a fake editor replacing "1.txt" by "2.txt"
|
||||
And I run :edit-url -b
|
||||
Then data/numbers/2.txt should be loaded
|
||||
And the following tabs should be open:
|
||||
- data/numbers/1.txt (active)
|
||||
- data/numbers/2.txt
|
||||
|
||||
Scenario: Editing an URL with -w
|
||||
When I open data/numbers/1.txt in a new tab
|
||||
And I run :tab-only
|
||||
And I set up a fake editor replacing "1.txt" by "2.txt"
|
||||
And I run :edit-url -w
|
||||
Then data/numbers/2.txt should be loaded
|
||||
And the session should look like:
|
||||
windows:
|
||||
- tabs:
|
||||
- active: true
|
||||
history:
|
||||
- active: true
|
||||
url: http://localhost:*/data/numbers/1.txt
|
||||
- tabs:
|
||||
- active: true
|
||||
history:
|
||||
- active: true
|
||||
url: http://localhost:*/data/numbers/2.txt
|
||||
|
||||
Scenario: Editing an URL with count
|
||||
Given I have a fresh instance
|
||||
When I open data/numbers/1.txt
|
||||
And I run :tab-only
|
||||
And I open about:blank in a new tab
|
||||
And I run :tab-focus 1
|
||||
And I set up a fake editor replacing "1.txt" by "2.txt"
|
||||
And I run :edit-url with count 2
|
||||
Then data/numbers/2.txt should be loaded
|
||||
And the following tabs should be open:
|
||||
- data/numbers/1.txt (active)
|
||||
- data/numbers/2.txt
|
||||
|
||||
Scenario: Editing an URL with -t and -b
|
||||
When I run :edit-url -t -b
|
||||
Then the error "Only one of -t/-b/-w can be given!" should be shown
|
||||
|
||||
Scenario: Editing an URL with invalid URL
|
||||
When I set general -> auto-search to false
|
||||
And I open data/hello.txt
|
||||
And I set up a fake editor replacing "http://localhost:(port)/data/hello.txt" by "foo!"
|
||||
And I run :edit-url
|
||||
Then the error "Invalid URL" should be shown
|
45
tests/integration/features/test_editor.py
Normal file
45
tests/integration/features/test_editor.py
Normal file
@ -0,0 +1,45 @@
|
||||
# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
|
||||
|
||||
# Copyright 2016 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
|
||||
#
|
||||
# This file is part of qutebrowser.
|
||||
#
|
||||
# qutebrowser is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# qutebrowser is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import sys
|
||||
import textwrap
|
||||
|
||||
import pytest_bdd as bdd
|
||||
bdd.scenarios('editor.feature')
|
||||
|
||||
|
||||
@bdd.when(bdd.parsers.parse('I set up a fake editor replacing "{text}" by '
|
||||
'"{replacement}"'))
|
||||
def set_up_editor_replacement(quteproc, httpbin, tmpdir, text, replacement):
|
||||
"""Set up general -> editor to a small python script doing a replacement"""
|
||||
text = text.replace('(port)', str(httpbin.port))
|
||||
script = tmpdir / 'script.py'
|
||||
script.write(textwrap.dedent("""
|
||||
import sys
|
||||
|
||||
with open(sys.argv[1], encoding='utf-8') as f:
|
||||
data = f.read()
|
||||
|
||||
data = data.replace("{text}", "{replacement}")
|
||||
|
||||
with open(sys.argv[1], 'w', encoding='utf-8') as f:
|
||||
f.write(data)
|
||||
""".format(text=text, replacement=replacement)))
|
||||
editor = '"{}" "{}" {{}}'.format(sys.executable, script)
|
||||
quteproc.set_setting('general', 'editor', editor)
|
Loading…
Reference in New Issue
Block a user