From 86dec02fe806dd5f25147c667ef24dbf86f00c7f Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 6 Apr 2016 06:47:19 +0200 Subject: [PATCH] bdd: Add tests for :edit-url --- tests/integration/features/editor.feature | 72 +++++++++++++++++++++++ tests/integration/features/test_editor.py | 45 ++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 tests/integration/features/editor.feature create mode 100644 tests/integration/features/test_editor.py diff --git a/tests/integration/features/editor.feature b/tests/integration/features/editor.feature new file mode 100644 index 000000000..ef3798564 --- /dev/null +++ b/tests/integration/features/editor.feature @@ -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 diff --git a/tests/integration/features/test_editor.py b/tests/integration/features/test_editor.py new file mode 100644 index 000000000..2fc76eb89 --- /dev/null +++ b/tests/integration/features/test_editor.py @@ -0,0 +1,45 @@ +# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: + +# Copyright 2016 Florian Bruhin (The Compiler) +# +# 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 . + +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)