To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / .svn / pristine / 44 / 442d530956f824ed60db31e2a2348cc1a58252b8.svn-base @ 1297:0a574315af3e
History | View | Annotate | Download (2.41 KB)
| 1 | 1296:038ba2d95de8 | Chris | # Redmine - project management software |
|---|---|---|---|
| 2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
||
| 3 | # |
||
| 4 | # This program is free software; you can redistribute it and/or |
||
| 5 | # modify it under the terms of the GNU General Public License |
||
| 6 | # as published by the Free Software Foundation; either version 2 |
||
| 7 | # of the License, or (at your option) any later version. |
||
| 8 | # |
||
| 9 | # This program is distributed in the hope that it will be useful, |
||
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
| 12 | # GNU General Public License for more details. |
||
| 13 | # |
||
| 14 | # You should have received a copy of the GNU General Public License |
||
| 15 | # along with this program; if not, write to the Free Software |
||
| 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||
| 17 | |||
| 18 | require File.expand_path('../../../test_helper', __FILE__)
|
||
| 19 | |||
| 20 | module RedminePmTest |
||
| 21 | class TestCase < ActiveSupport::TestCase |
||
| 22 | attr_reader :command, :response, :status, :username, :password |
||
| 23 | |||
| 24 | # Cannot use transactional fixtures here: database |
||
| 25 | # will be accessed from Redmine.pm with its own connection |
||
| 26 | self.use_transactional_fixtures = false |
||
| 27 | |||
| 28 | def test_dummy |
||
| 29 | end |
||
| 30 | |||
| 31 | protected |
||
| 32 | |||
| 33 | def assert_response(expected, msg=nil) |
||
| 34 | case expected |
||
| 35 | when :success |
||
| 36 | assert_equal 0, status, |
||
| 37 | (msg || "The command failed (exit: #{status}):\n #{command}\nOutput was:\n#{formatted_response}")
|
||
| 38 | when :failure |
||
| 39 | assert_not_equal 0, status, |
||
| 40 | (msg || "The command succeed (exit: #{status}):\n #{command}\nOutput was:\n#{formatted_response}")
|
||
| 41 | else |
||
| 42 | assert_equal expected, status, msg |
||
| 43 | end |
||
| 44 | end |
||
| 45 | |||
| 46 | def assert_success(*args) |
||
| 47 | execute *args |
||
| 48 | assert_response :success |
||
| 49 | end |
||
| 50 | |||
| 51 | def assert_failure(*args) |
||
| 52 | execute *args |
||
| 53 | assert_response :failure |
||
| 54 | end |
||
| 55 | |||
| 56 | def with_credentials(username, password) |
||
| 57 | old_username, old_password = @username, @password |
||
| 58 | @username, @password = username, password |
||
| 59 | yield if block_given? |
||
| 60 | ensure |
||
| 61 | @username, @password = old_username, old_password |
||
| 62 | end |
||
| 63 | |||
| 64 | def execute(*args) |
||
| 65 | @command = args.join(' ')
|
||
| 66 | @status = nil |
||
| 67 | IO.popen("#{command} 2>&1") do |io|
|
||
| 68 | @response = io.read |
||
| 69 | end |
||
| 70 | @status = $?.exitstatus |
||
| 71 | end |
||
| 72 | |||
| 73 | def formatted_response |
||
| 74 | "#{'='*40}\n#{response}#{'='*40}"
|
||
| 75 | end |
||
| 76 | |||
| 77 | def random_filename |
||
| 78 | Redmine::Utils.random_hex(16) |
||
| 79 | end |
||
| 80 | end |
||
| 81 | end |