aktion_test 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +6 -0
- data/README.md +4 -1
- data/lib/aktion_test/class_builder.rb +31 -0
- data/lib/aktion_test/matchers/file_system/be_a_directory.rb +9 -1
- data/lib/aktion_test/matchers/file_system/be_a_file.rb +20 -4
- data/lib/aktion_test/matchers/file_system/directory_contains.rb +0 -18
- data/lib/aktion_test/version.rb +1 -1
- data/lib/aktion_test.rb +3 -0
- data/spec/aktion_test/class_builder_spec.rb +30 -0
- data/spec/matchers/base_spec.rb +51 -0
- data/spec/matchers/be_a_directory_spec.rb +53 -6
- data/spec/matchers/be_a_file_spec.rb +53 -6
- data/spec/matchers/directory_contains_spec.rb +24 -0
- data/spec/spec_helper.rb +8 -0
- metadata +7 -2
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# AktionTest
|
2
2
|
|
3
|
-
|
3
|
+
[](https://travis-ci.org/AktionLab/aktion_test)
|
4
|
+
[](https://gemnasium.com/AktionLab/aktion_test)
|
5
|
+
|
6
|
+
Testing gem that includes a common set of testing gem and a suite of RSpec Matchers
|
4
7
|
|
5
8
|
## Installation
|
6
9
|
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'active_support/dependencies'
|
2
|
+
|
3
|
+
module AktionTest
|
4
|
+
module ClassBuilder
|
5
|
+
def self.included(example_group)
|
6
|
+
example_group.class_eval do
|
7
|
+
after do
|
8
|
+
teardown_defined_constants
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def define_class(class_name, base = Object, &block)
|
14
|
+
class_name = class_name.to_s.camelize
|
15
|
+
|
16
|
+
Class.new(base).tap do |constant_class|
|
17
|
+
Object.const_set(class_name, constant_class)
|
18
|
+
constant_class.unloadable
|
19
|
+
constant_class.class_eval(&block) if block_given?
|
20
|
+
constant_class.reset_column_information if constant_class.respond_to? :reset_column_information
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def teardown_defined_constants
|
25
|
+
ActiveSupport::Dependencies.clear
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
RSpec.configure {|config| config.include AktionTest::ClassBuilder}
|
31
|
+
|
@@ -21,7 +21,15 @@ module AktionTest
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def problem
|
24
|
-
|
24
|
+
if File.exists? @subject
|
25
|
+
unless File.directory? @subject
|
26
|
+
"#{@subject} is not a directory."
|
27
|
+
else
|
28
|
+
"Unknown"
|
29
|
+
end
|
30
|
+
else
|
31
|
+
"#{@subject} does not exist."
|
32
|
+
end
|
25
33
|
end
|
26
34
|
|
27
35
|
def directory_exists?
|
@@ -11,17 +11,33 @@ module AktionTest
|
|
11
11
|
|
12
12
|
def matches?(subject)
|
13
13
|
@subject = subject
|
14
|
-
|
14
|
+
file_exists? and file_is_not_a_directory?
|
15
15
|
end
|
16
16
|
|
17
17
|
protected
|
18
|
-
|
18
|
+
|
19
19
|
def expectation
|
20
|
-
"#{@subject} to be a file"
|
20
|
+
"#{@subject} to be a file."
|
21
21
|
end
|
22
22
|
|
23
23
|
def problem
|
24
|
-
|
24
|
+
if File.exists?(@subject)
|
25
|
+
if File.directory?(@subject)
|
26
|
+
"#{@subject} is a directory."
|
27
|
+
else
|
28
|
+
"Unknown"
|
29
|
+
end
|
30
|
+
else
|
31
|
+
"#{@subject} does not exist."
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def file_exists?
|
36
|
+
File.exists? @subject
|
37
|
+
end
|
38
|
+
|
39
|
+
def file_is_not_a_directory?
|
40
|
+
!File.directory? @subject
|
25
41
|
end
|
26
42
|
end
|
27
43
|
end
|
@@ -2,30 +2,12 @@ module AktionTest
|
|
2
2
|
module Matchers
|
3
3
|
module FileSystem
|
4
4
|
def have_file(path)
|
5
|
-
# 'some_file' : ['some_file']
|
6
|
-
# 'some_dir/some_file' : [{'some_dir' => ['some_file']}]
|
7
|
-
# '*/some_file' : [{'*' => ['some_file']}]
|
8
|
-
# '**/some_file' : [{'**' => ['some_file']}]
|
9
|
-
# 'some_dir/*/some_file' :
|
10
5
|
segments = path.split('/')
|
11
6
|
file = segments.pop
|
12
7
|
tree = segments.reverse.reduce([file]) {|a,b| [{b => a}] }
|
13
8
|
have_tree(tree)
|
14
9
|
end
|
15
10
|
|
16
|
-
def have_files(files)
|
17
|
-
# have_tree([{'**' => files}])
|
18
|
-
DirectoryContentMatcher.new(files)
|
19
|
-
end
|
20
|
-
|
21
|
-
def have_directory(dir)
|
22
|
-
# have_tree([{'**' => [{dir => []}]}])
|
23
|
-
end
|
24
|
-
|
25
|
-
def have_directories(dirs)
|
26
|
-
# have_tree([{'**' => [Hash[a.zip(a.size.times.map{[]})]]}])
|
27
|
-
end
|
28
|
-
|
29
11
|
def have_tree(tree)
|
30
12
|
DirectoryContentMatcher.new(tree)
|
31
13
|
end
|
data/lib/aktion_test/version.rb
CHANGED
data/lib/aktion_test.rb
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AktionTest::ClassBuilder do
|
4
|
+
it "creates a new class" do
|
5
|
+
clazz = define_class('Foo')
|
6
|
+
clazz.new.should be_a Foo
|
7
|
+
end
|
8
|
+
|
9
|
+
it "creates a new class with a base" do
|
10
|
+
base = define_class('Foo')
|
11
|
+
clazz = define_class('Bar', Foo)
|
12
|
+
clazz.superclass.should == Foo
|
13
|
+
end
|
14
|
+
|
15
|
+
it "creates a new class and class evals a block" do
|
16
|
+
clazz = define_class('Foo') do
|
17
|
+
class << self
|
18
|
+
def foo
|
19
|
+
"baz"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
attr_accessor :bar
|
24
|
+
end
|
25
|
+
|
26
|
+
clazz.foo.should == 'baz'
|
27
|
+
clazz.new.should respond_to :bar
|
28
|
+
clazz.new.should respond_to :bar=
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AktionTest::Matchers::Base do
|
4
|
+
it "requires the extending class to implement #expectation" do
|
5
|
+
matcher = define_class('Matcher', described_class)
|
6
|
+
expect { matcher.new.failure_message }.to raise_error(NameError, /`expectation'/)
|
7
|
+
expect { matcher.new.negative_failure_message }.to raise_error(NameError, /`expectation'/)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "requires the extending class to implement #problem" do
|
11
|
+
matcher = define_class('Matcher', described_class) do
|
12
|
+
protected
|
13
|
+
def expectation
|
14
|
+
''
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
expect { matcher.new.failure_message }.to raise_error(NameError, /`problem'/)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "provides a failure message based on #expectation and #problem" do
|
22
|
+
matcher = define_class('Matcher', described_class) do
|
23
|
+
protected
|
24
|
+
def expectation
|
25
|
+
'an expectation'
|
26
|
+
end
|
27
|
+
|
28
|
+
def problem
|
29
|
+
'A Problem'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
matcher.new.failure_message.should == <<-MSG.strip_heredoc.strip
|
34
|
+
Expected an expectation
|
35
|
+
A Problem
|
36
|
+
MSG
|
37
|
+
end
|
38
|
+
|
39
|
+
it "provides a negative failure message based on #expectation" do
|
40
|
+
matcher = define_class('Matcher', described_class) do
|
41
|
+
protected
|
42
|
+
def expectation
|
43
|
+
'an expectation'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
matcher.new.negative_failure_message.should == <<-MSG.strip_heredoc.strip
|
48
|
+
Did not expect an expectation
|
49
|
+
MSG
|
50
|
+
end
|
51
|
+
end
|
@@ -1,15 +1,62 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe AktionTest::Matchers::FileSystem::DirectoryExistanceMatcher do
|
4
|
-
|
5
|
-
File.expand_path(File.join(__FILE__, '..'))
|
4
|
+
context "an existing directory" do
|
5
|
+
let(:dir) { File.expand_path(File.join(__FILE__, '..')) }
|
6
|
+
|
7
|
+
it "will be accepeted" do
|
8
|
+
dir.should be_a_directory
|
9
|
+
end
|
10
|
+
|
11
|
+
it "provides a negative failure message" do
|
12
|
+
matcher = described_class.new
|
13
|
+
matcher.matches?(dir)
|
14
|
+
matcher.negative_failure_message.should == <<-MSG.strip_heredoc.strip
|
15
|
+
Did not expect #{dir} to be a directory.
|
16
|
+
MSG
|
17
|
+
end
|
18
|
+
|
19
|
+
it "provides a failure message with an unknown problem" do
|
20
|
+
matcher = described_class.new
|
21
|
+
matcher.matches?(dir)
|
22
|
+
matcher.failure_message.should == <<-MSG.strip_heredoc.strip
|
23
|
+
Expected #{dir} to be a directory.
|
24
|
+
Unknown
|
25
|
+
MSG
|
26
|
+
end
|
6
27
|
end
|
7
28
|
|
8
|
-
|
9
|
-
File.expand_path(File.join(__FILE__, '..', 'foo'))
|
29
|
+
context "a non-existant directory" do
|
30
|
+
let(:dir) { File.expand_path(File.join(__FILE__, '..', 'foo')) }
|
31
|
+
|
32
|
+
it "will not be accepted" do
|
33
|
+
dir.should_not be_a_directory
|
34
|
+
end
|
35
|
+
|
36
|
+
it "explains that the subject does not exist" do
|
37
|
+
matcher = described_class.new
|
38
|
+
matcher.matches?(dir)
|
39
|
+
matcher.failure_message.should == <<-MSG.strip_heredoc.strip
|
40
|
+
Expected #{dir} to be a directory.
|
41
|
+
#{dir} does not exist.
|
42
|
+
MSG
|
43
|
+
end
|
10
44
|
end
|
11
45
|
|
12
|
-
|
13
|
-
__FILE__
|
46
|
+
context "a file" do
|
47
|
+
let(:dir) { __FILE__ }
|
48
|
+
|
49
|
+
it "will not be accepted" do
|
50
|
+
dir.should_not be_a_directory
|
51
|
+
end
|
52
|
+
|
53
|
+
it "explains that the subject is a file" do
|
54
|
+
matcher = described_class.new
|
55
|
+
matcher.matches?(dir)
|
56
|
+
matcher.failure_message.should == <<-MSG.strip_heredoc.strip
|
57
|
+
Expected #{dir} to be a directory.
|
58
|
+
#{dir} is not a directory.
|
59
|
+
MSG
|
60
|
+
end
|
14
61
|
end
|
15
62
|
end
|
@@ -1,15 +1,62 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe AktionTest::Matchers::FileSystem::FileExistanceMatcher do
|
4
|
-
|
5
|
-
__FILE__
|
4
|
+
context "an existing file" do
|
5
|
+
let(:file) { __FILE__ }
|
6
|
+
|
7
|
+
it "will be accepted" do
|
8
|
+
file.should be_a_file
|
9
|
+
end
|
10
|
+
|
11
|
+
it "provides a negative failure message" do
|
12
|
+
matcher = described_class.new
|
13
|
+
matcher.matches?(file)
|
14
|
+
matcher.negative_failure_message.should == <<-MSG.strip_heredoc.strip
|
15
|
+
Did not expect #{file} to be a file.
|
16
|
+
MSG
|
17
|
+
end
|
18
|
+
|
19
|
+
it "provides a failure message with an unknown problem" do
|
20
|
+
matcher = described_class.new
|
21
|
+
matcher.matches?(file)
|
22
|
+
matcher.failure_message.should == <<-MSG.strip_heredoc.strip
|
23
|
+
Expected #{file} to be a file.
|
24
|
+
Unknown
|
25
|
+
MSG
|
26
|
+
end
|
6
27
|
end
|
7
28
|
|
8
|
-
|
9
|
-
File.join(__FILE__, '..', 'foo')
|
29
|
+
context "a non-existant file" do
|
30
|
+
let(:file) { File.expand_path(File.join(__FILE__, '..', 'foo')) }
|
31
|
+
|
32
|
+
it "will not be accepted" do
|
33
|
+
file.should_not be_a_file
|
34
|
+
end
|
35
|
+
|
36
|
+
it "explains that the subject does not exist" do
|
37
|
+
matcher = described_class.new
|
38
|
+
matcher.matches?(file)
|
39
|
+
matcher.failure_message.should == <<-MSG.strip_heredoc.strip
|
40
|
+
Expected #{file} to be a file.
|
41
|
+
#{file} does not exist.
|
42
|
+
MSG
|
43
|
+
end
|
10
44
|
end
|
11
45
|
|
12
|
-
|
13
|
-
File.join(__FILE__, '..')
|
46
|
+
context "an existing directory" do
|
47
|
+
let(:file) { File.expand_path(File.join(__FILE__, '..')) }
|
48
|
+
|
49
|
+
it "will not be accpeted" do
|
50
|
+
file.should_not be_a_file
|
51
|
+
end
|
52
|
+
|
53
|
+
it "explains that the subject is a directory" do
|
54
|
+
matcher = described_class.new
|
55
|
+
matcher.matches?(file)
|
56
|
+
matcher.failure_message.should == <<-MSG.strip_heredoc.strip
|
57
|
+
Expected #{file} to be a file.
|
58
|
+
#{file} is a directory.
|
59
|
+
MSG
|
60
|
+
end
|
14
61
|
end
|
15
62
|
end
|
@@ -25,6 +25,30 @@ describe AktionTest::Matchers::FileSystem::DirectoryContentMatcher do
|
|
25
25
|
@matcher ||= described_class.new(*args)
|
26
26
|
end
|
27
27
|
|
28
|
+
context "with a matching tree" do
|
29
|
+
it "provides a negative failure message" do
|
30
|
+
build(['test_file'])
|
31
|
+
matcher = described_class.new(['test_file'])
|
32
|
+
matcher.matches?(test_root)
|
33
|
+
matcher.negative_failure_message.should == <<-MSG.strip_heredoc
|
34
|
+
Did not expect #{test_root} to contain:
|
35
|
+
test_file
|
36
|
+
MSG
|
37
|
+
end
|
38
|
+
|
39
|
+
it "provides a failure message with an unknown problem" do
|
40
|
+
build(['test_file'])
|
41
|
+
matcher = described_class.new(['test_file'])
|
42
|
+
matcher.matches?(test_root)
|
43
|
+
matcher.failure_message.should == <<-MSG.strip_heredoc.strip
|
44
|
+
Expected #{test_root} to contain:
|
45
|
+
test_file
|
46
|
+
|
47
|
+
Unknown Problem
|
48
|
+
MSG
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
28
52
|
context "single file in the root" do
|
29
53
|
it "will accept if the file exists" do
|
30
54
|
build(['test_file'])
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aktion_test
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -110,12 +110,15 @@ files:
|
|
110
110
|
- Rakefile
|
111
111
|
- aktion_test.gemspec
|
112
112
|
- lib/aktion_test.rb
|
113
|
+
- lib/aktion_test/class_builder.rb
|
113
114
|
- lib/aktion_test/matchers/base.rb
|
114
115
|
- lib/aktion_test/matchers/file_system/be_a_directory.rb
|
115
116
|
- lib/aktion_test/matchers/file_system/be_a_file.rb
|
116
117
|
- lib/aktion_test/matchers/file_system/directory_contains.rb
|
117
118
|
- lib/aktion_test/matchers/integrations/rspec.rb
|
118
119
|
- lib/aktion_test/version.rb
|
120
|
+
- spec/aktion_test/class_builder_spec.rb
|
121
|
+
- spec/matchers/base_spec.rb
|
119
122
|
- spec/matchers/be_a_directory_spec.rb
|
120
123
|
- spec/matchers/be_a_file_spec.rb
|
121
124
|
- spec/matchers/directory_contains_spec.rb
|
@@ -146,6 +149,8 @@ signing_key:
|
|
146
149
|
specification_version: 3
|
147
150
|
summary: Gems, libs, helpers for test suites.
|
148
151
|
test_files:
|
152
|
+
- spec/aktion_test/class_builder_spec.rb
|
153
|
+
- spec/matchers/base_spec.rb
|
149
154
|
- spec/matchers/be_a_directory_spec.rb
|
150
155
|
- spec/matchers/be_a_file_spec.rb
|
151
156
|
- spec/matchers/directory_contains_spec.rb
|