Skip to content

Commit b597cbb

Browse files
committed
Rewrite test files from test-unit to rspec
1 parent 6dcf64e commit b597cbb

10 files changed

+85
-87
lines changed

.rspec

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--color
2+
--require spec_helper

.rubocop_todo.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Style/BlockDelimiters:
3838
# Configuration parameters: EnforcedStyle, SupportedStyles.
3939
Style/ClassAndModuleChildren:
4040
Exclude:
41-
- 'test/test_helper.rb'
41+
- 'test/spec_helper.rb'
4242

4343
# Offense count: 24
4444
Style/Documentation:

Rakefile

+3-9
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22
require "bundler"
33
Bundler::GemHelper.install_tasks
44

5-
task :default => :test
6-
7-
require "rake/testtask"
8-
Rake::TestTask.new do |t|
9-
t.libs << "test"
10-
# t.test_files = FileList['test/test*.rb']
11-
# t.verbose = true
12-
# t.options = "--no-use-color"
13-
end
5+
require "rspec/core/rake_task"
6+
RSpec::Core::RakeTask.new
7+
task :default => :spec

test/test_ar_tree_model.rb renamed to spec/ar_tree_model_spec.rb

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
require "test_helper"
2+
require "spec_helper"
33

44
require "rails"
55
require "tree_support/ar_tree_model"
@@ -8,8 +8,8 @@
88

99
Class.new(Rails::Application){config.eager_load = true}.initialize!
1010

11-
class TestArTreeModel < Test::Unit::TestCase
12-
setup do
11+
RSpec.describe "ArTreeModel" do
12+
before do
1313
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
1414
ActiveRecord::Migration.verbose = false
1515

@@ -64,20 +64,20 @@ def add(name, &block)
6464
end
6565
end
6666

67-
test "roots" do
68-
assert_equal [@node], Node.roots
67+
it "roots" do
68+
Node.roots.should == [@node]
6969
end
7070

71-
test "root" do
72-
assert_equal @node, Node.root
71+
it "root" do
72+
Node.root.should == @node
7373
end
7474

75-
test "to_s_tree" do
75+
it "to_s_tree" do
7676
@node.to_s_tree
7777
end
7878

79-
test "safe_destroy_all" do
79+
it "safe_destroy_all" do
8080
Node.safe_destroy_all
81-
assert_equal 0, Node.count
81+
Node.count.should == 0
8282
end
8383
end

spec/spec_helper.rb

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
2+
require "tree_support"
3+
4+
RSpec.configure do |config|
5+
config.expect_with :rspec do |expectations|
6+
expectations.syntax = [:should, :expect]
7+
end
8+
end

test/test_tree_support.rb renamed to spec/tree_support_spec.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# -*- coding: utf-8 -*-
2-
require "test_helper"
2+
require "spec_helper"
33

4-
class TestTreeSupport < Test::Unit::TestCase
5-
test "tree" do
4+
RSpec.describe "TreeSupport" do
5+
it "tree" do
66
expected = <<-EOT
77
*root*
88
├─交戦
@@ -24,6 +24,6 @@ class TestTreeSupport < Test::Unit::TestCase
2424
├─回復魔法
2525
└─回復薬を飲む
2626
EOT
27-
assert_equal expected, TreeSupport.example.to_s_tree
27+
TreeSupport.example.to_s_tree.should == expected
2828
end
2929
end

spec/treeable_spec.rb

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# -*- coding: utf-8 -*-
2+
require "spec_helper"
3+
4+
RSpec.describe "Treeable" do
5+
before do
6+
@root = TreeSupport::Node.new("*root*") do
7+
add "a" do
8+
add "a1"
9+
add "a2" do
10+
add "x"
11+
end
12+
add "a3"
13+
end
14+
end
15+
@a2 = @root.each_node.find {|e| e.name == "a2"}
16+
@leaf = @root.each_node.find {|e| e.name == "x"}
17+
end
18+
19+
it "ancestors" do
20+
@a2.ancestors.collect(&:name).should == ["a2", "a", "*root*"]
21+
end
22+
23+
it "descendants" do
24+
@root.descendants.collect(&:name).should == ["a", "a1", "a2", "x", "a3"]
25+
end
26+
27+
it "self_and_descendants" do
28+
@root.self_and_descendants.collect(&:name).should == ["*root*", "a", "a1", "a2", "x", "a3"]
29+
end
30+
31+
it "each_node" do
32+
@root.each_node.collect(&:name).should == ["*root*", "a", "a1", "a2", "x", "a3"]
33+
end
34+
35+
it "root" do
36+
@a2.root.name.should == "*root*"
37+
end
38+
39+
it "siblings" do
40+
@a2.siblings.collect(&:name).should == ["a1", "a3"]
41+
end
42+
43+
it "self_and_siblings" do
44+
@a2.self_and_siblings.collect(&:name).should == ["a1", "a2", "a3"]
45+
end
46+
47+
it "root?" do
48+
@root.root?.should == true
49+
@leaf.root?.should == false
50+
end
51+
52+
it "leaf?" do
53+
@root.leaf?.should == false
54+
@leaf.leaf?.should == true
55+
end
56+
end

test/test_helper.rb

-6
This file was deleted.

test/test_treeable.rb

-56
This file was deleted.

tree_support.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Gem::Specification.new do |s|
2222
s.add_dependency "activesupport"
2323

2424
s.add_development_dependency "rake"
25-
s.add_development_dependency "test-unit"
25+
s.add_development_dependency "rspec"
2626
s.add_development_dependency "rails"
2727
s.add_development_dependency "activerecord"
2828
s.add_development_dependency "sqlite3"

0 commit comments

Comments
 (0)