Commit e81d08b31e09a6836ccc3deab9cd0f555e31f3b5
1 parent
f4aa3784
Exists in
master
and in
29 other branches
Abstrating documentation tests
They are need in DocControlller tests as well in order to not depend on the docs being built during tests
Showing
4 changed files
with
56 additions
and
32 deletions
Show diff stats
test/functional/doc_controller_test.rb
@@ -2,6 +2,16 @@ require File.dirname(__FILE__) + '/../test_helper' | @@ -2,6 +2,16 @@ require File.dirname(__FILE__) + '/../test_helper' | ||
2 | 2 | ||
3 | class DocControllerTest < ActionController::TestCase | 3 | class DocControllerTest < ActionController::TestCase |
4 | 4 | ||
5 | + include Noosfero::DocTest | ||
6 | + | ||
7 | + def setup | ||
8 | + setup_doc_test | ||
9 | + end | ||
10 | + | ||
11 | + def tear_down | ||
12 | + tear_down_doc_test | ||
13 | + end | ||
14 | + | ||
5 | should 'load toc in the root' do | 15 | should 'load toc in the root' do |
6 | get :index | 16 | get :index |
7 | assert_kind_of DocItem, assigns(:toc) | 17 | assert_kind_of DocItem, assigns(:toc) |
@@ -0,0 +1,42 @@ | @@ -0,0 +1,42 @@ | ||
1 | +module Noosfero::DocTest | ||
2 | + | ||
3 | + ROOT = File.join(Rails.root, "test", "tmp", "doc") | ||
4 | + | ||
5 | + def create_doc(section, topic, language, title) | ||
6 | + dir = File.join(ROOT, section) | ||
7 | + FileUtils.mkdir_p(dir) | ||
8 | + File.open("#{dir}/#{topic}.#{language}.xhtml", "w") do |f| | ||
9 | + f.puts "<h1>#{title}</h1>" | ||
10 | + end | ||
11 | + end | ||
12 | + | ||
13 | + def setup_doc_test | ||
14 | + FileUtils.mkdir_p(ROOT) | ||
15 | + | ||
16 | + # root | ||
17 | + create_doc('', 'index', 'en', 'Root') | ||
18 | + create_doc('', 'toc', 'en', 'Root') | ||
19 | + # cms | ||
20 | + create_doc('cms', 'index', 'en', 'Content Management') | ||
21 | + create_doc('cms', 'index', 'pt', 'Gerenciamento de conteúdo') | ||
22 | + create_doc('cms', 'toc', 'en', '') | ||
23 | + create_doc('cms', 'toc', 'pt', '') | ||
24 | + create_doc('cms', 'adding-pictures', 'en', 'Adding pictures to gallery') | ||
25 | + create_doc('cms', 'adding-pictures', 'pt', 'Adicionando fotos na galeria') | ||
26 | + create_doc('cms', 'creating-a-blog', 'en', 'Creating a blog') | ||
27 | + create_doc('cms', 'creating-a-blog', 'pt', 'Criando um blog') | ||
28 | + # user | ||
29 | + create_doc('user', 'index', 'en', 'User features') | ||
30 | + create_doc('user', 'index', 'pt', 'Funcionalidades de Usuário') | ||
31 | + create_doc('user', 'toc', 'en', '') | ||
32 | + create_doc('user', 'toc', 'pt', '') | ||
33 | + create_doc('user', 'accepting-friends', 'en', 'Accepting friends') | ||
34 | + create_doc('user', 'accepting-friends', 'pt', 'Aceitando amigos') | ||
35 | + | ||
36 | + DocSection.stubs(:root_dir).returns(ROOT) | ||
37 | + end | ||
38 | + | ||
39 | + def tear_down_doc_test | ||
40 | + FileUtils.rm_rf(ROOT) | ||
41 | + end | ||
42 | +end |
test/test_helper.rb
@@ -7,6 +7,7 @@ require 'hpricot' | @@ -7,6 +7,7 @@ require 'hpricot' | ||
7 | 7 | ||
8 | require 'noosfero/test' | 8 | require 'noosfero/test' |
9 | require File.dirname(__FILE__) + '/factories' | 9 | require File.dirname(__FILE__) + '/factories' |
10 | +require File.dirname(__FILE__) + '/noosfero_doc_test' | ||
10 | 11 | ||
11 | FileUtils.rm_rf(File.join(RAILS_ROOT, 'index', 'test')) | 12 | FileUtils.rm_rf(File.join(RAILS_ROOT, 'index', 'test')) |
12 | 13 |
test/unit/doc_section_test.rb
@@ -2,43 +2,14 @@ require 'test_helper' | @@ -2,43 +2,14 @@ require 'test_helper' | ||
2 | 2 | ||
3 | class DocSectionTest < ActiveSupport::TestCase | 3 | class DocSectionTest < ActiveSupport::TestCase |
4 | 4 | ||
5 | - ROOT = File.join(Rails.root, "test", "tmp", "doc") | ||
6 | - | ||
7 | - def create_doc(section, topic, language, title) | ||
8 | - dir = File.join(ROOT, section) | ||
9 | - FileUtils.mkdir_p(dir) | ||
10 | - File.open("#{dir}/#{topic}.#{language}.xhtml", "w") do |f| | ||
11 | - f.puts "<h1>#{title}</h1>" | ||
12 | - end | ||
13 | - end | 5 | + include Noosfero::DocTest |
14 | 6 | ||
15 | def setup | 7 | def setup |
16 | - FileUtils.mkdir_p(ROOT) | ||
17 | - | ||
18 | - # root | ||
19 | - create_doc('', 'index', 'en', 'Root') | ||
20 | - create_doc('', 'toc', 'en', 'Root') | ||
21 | - # cms | ||
22 | - create_doc('cms', 'index', 'en', 'Content Management') | ||
23 | - create_doc('cms', 'index', 'pt', 'Gerenciamento de conteúdo') | ||
24 | - create_doc('cms', 'toc', 'en', '') | ||
25 | - create_doc('cms', 'toc', 'pt', '') | ||
26 | - create_doc('cms', 'adding-pictures', 'en', 'Adding pictures to gallery') | ||
27 | - create_doc('cms', 'adding-pictures', 'pt', 'Adicionando fotos na galeria') | ||
28 | - create_doc('cms', 'creating-a-blog', 'en', 'Creating a blog') | ||
29 | - create_doc('cms', 'creating-a-blog', 'pt', 'Criando um blog') | ||
30 | - # user | ||
31 | - create_doc('user', 'index', 'en', 'User features') | ||
32 | - create_doc('user', 'index', 'pt', 'Funcionalidades de Usuário') | ||
33 | - create_doc('user', 'toc', 'en', '') | ||
34 | - create_doc('user', 'toc', 'pt', '') | ||
35 | - create_doc('user', 'accepting-friends', 'en', 'Accepting friends') | ||
36 | - | ||
37 | - DocSection.stubs(:root_dir).returns(ROOT) | 8 | + setup_doc_test |
38 | end | 9 | end |
39 | 10 | ||
40 | def tear_down | 11 | def tear_down |
41 | - FileUtils.rm_rf(ROOT) | 12 | + tear_down_doc_test |
42 | end | 13 | end |
43 | 14 | ||
44 | should 'be a DocItem' do | 15 | should 'be a DocItem' do |