aktion_test 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 1.9.2
3
+ - 1.9.3
4
+
5
+ script: "bundle exec rake"
6
+
data/CHANGELOG.md ADDED
@@ -0,0 +1,15 @@
1
+ # v0.1.0
2
+
3
+ Addition of RSpec matchers
4
+ * Matcher to check for file existance
5
+ * Matcher to check for directory existance
6
+ * Matcher to check the contents of a directory tree
7
+
8
+ # v0.0.2
9
+ * bump gem versions
10
+ * remove cucumber
11
+
12
+ # v0.0.1
13
+ Initial Release
14
+
15
+ * Provides some basic testing gem dependencies
data/Gemfile CHANGED
@@ -1,4 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ gem 'rake', '~> 10.0.2'
3
4
  # Specify your gem's dependencies in aktion_test.gemspec
4
5
  gemspec
data/Rakefile CHANGED
@@ -1,2 +1,15 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new do |t|
6
+ t.pattern = 'spec/**/*_spec.rb'
7
+ t.rspec_opts = '--color --format progress'
8
+ t.verbose = false
9
+ end
10
+
11
+ task :all do
12
+ exec('rake spec')
13
+ end
14
+
15
+ task :default => [:all]
data/aktion_test.gemspec CHANGED
@@ -7,6 +7,7 @@ Gem::Specification.new do |gem|
7
7
  gem.description = %q{Contains all required testing gems as well as some rake tasks and test helpers to make getting a test suite up and running easy and fast.}
8
8
  gem.summary = %q{Gems, libs, helpers for test suites.}
9
9
  gem.homepage = "http://aktionlab.com"
10
+ gem.license = 'MIT'
10
11
 
11
12
  gem.files = `git ls-files`.split($\)
12
13
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -15,6 +16,8 @@ Gem::Specification.new do |gem|
15
16
  gem.require_paths = ["lib"]
16
17
  gem.version = AktionTest::VERSION
17
18
 
19
+ gem.required_ruby_version = '~> 1.9.2'
20
+
18
21
  # Don't add anything to this list that depends on Rails or any
19
22
  # other large frameworks/orms. This list should be suitable for
20
23
  # even the simplest gem.
@@ -0,0 +1,13 @@
1
+ module AktionTest
2
+ module Matchers
3
+ class Base
4
+ def failure_message
5
+ "Expected #{expectation}\n#{problem}"
6
+ end
7
+
8
+ def negative_failure_message
9
+ "Did not expect #{expectation}"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,33 @@
1
+ module AktionTest
2
+ module Matchers
3
+ module FileSystem
4
+ def be_a_directory
5
+ DirectoryExistanceMatcher.new
6
+ end
7
+
8
+ class DirectoryExistanceMatcher < Matchers::Base
9
+ def initialize
10
+ end
11
+
12
+ def matches?(subject)
13
+ @subject = subject
14
+ directory_exists?
15
+ end
16
+
17
+ protected
18
+
19
+ def expectation
20
+ "#{@subject} to be a directory."
21
+ end
22
+
23
+ def problem
24
+ ""
25
+ end
26
+
27
+ def directory_exists?
28
+ Dir.exists? @subject
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,30 @@
1
+ module AktionTest
2
+ module Matchers
3
+ module FileSystem
4
+ def be_a_file
5
+ FileExistanceMatcher.new
6
+ end
7
+
8
+ class FileExistanceMatcher < Matchers::Base
9
+ def initialize
10
+ end
11
+
12
+ def matches?(subject)
13
+ @subject = subject
14
+ File.exists? @subject
15
+ end
16
+
17
+ protected
18
+
19
+ def expectation
20
+ "#{@subject} to be a file"
21
+ end
22
+
23
+ def problem
24
+ ""
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+
@@ -0,0 +1,118 @@
1
+ module AktionTest
2
+ module Matchers
3
+ module FileSystem
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
+ segments = path.split('/')
11
+ file = segments.pop
12
+ tree = segments.reverse.reduce([file]) {|a,b| [{b => a}] }
13
+ have_tree(tree)
14
+ end
15
+
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
+ def have_tree(tree)
30
+ DirectoryContentMatcher.new(tree)
31
+ end
32
+
33
+ class DirectoryContentMatcher < Matchers::Base
34
+ def initialize(tree)
35
+ @tree = tree
36
+ end
37
+
38
+ def matches?(subject)
39
+ @subject = subject
40
+ directory_exists? && matches_tree?(@tree)
41
+ end
42
+
43
+ protected
44
+
45
+ def matches_tree?(tree, directory='')
46
+ tree.all? do |entry|
47
+ if entry.is_a? String
48
+ Dir[File.join(@subject, directory, entry)].any?
49
+ elsif entry.is_a? Hash
50
+ entry.to_a.all?{|dir,subtree| matches_tree?(subtree, File.join(directory, dir))}
51
+ end
52
+ end
53
+ end
54
+
55
+ def directory_exists?
56
+ Dir.exists?(@subject)
57
+ end
58
+
59
+ def expectation
60
+ "#{@subject} to contain:\n#{print_tree}\n"
61
+ end
62
+
63
+ def flatten_tree(structure, directory='')
64
+ structure.map do |entry|
65
+ case entry
66
+ when Hash
67
+ entry.map{|dir,entries| flatten_tree(entries, "#{directory}#{dir}/")}
68
+ when String
69
+ "#{directory}#{entry}"
70
+ end
71
+ end.flatten
72
+ end
73
+
74
+ def problem
75
+ unless directory_exists?
76
+ if File.exists? @subject
77
+ "#{@subject} is not a directory."
78
+ else
79
+ "#{@subject} does not exist."
80
+ end
81
+ else
82
+ missing_files = flatten_tree(@tree).reject do |path|
83
+ Dir["#{@subject}/#{path}"].any?
84
+ end
85
+ if missing_files.any?
86
+ missing_files.map{|f| "#{f} was not found"}.join("\n")
87
+ else
88
+ "Unknown Problem"
89
+ end
90
+ end
91
+ end
92
+
93
+ def print_tree(tree=nil, depth=1)
94
+ tree ||= @tree
95
+ tree.map do |entry|
96
+ case entry
97
+ when String then
98
+ print_file(entry, depth)
99
+ when Hash
100
+ entry.map do |k,v|
101
+ print_directory(k, depth) + "\n" +
102
+ print_tree(v, depth + 1)
103
+ end.join("\n")
104
+ end
105
+ end.join("\n")
106
+ end
107
+
108
+ def print_file(file, depth)
109
+ "#{" " * depth}#{file}"
110
+ end
111
+
112
+ def print_directory(directory, depth)
113
+ print_file(directory + '/', depth)
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,7 @@
1
+ require 'aktion_test/matchers/file_system/be_a_file'
2
+ require 'aktion_test/matchers/file_system/be_a_directory'
3
+ require 'aktion_test/matchers/file_system/directory_contains'
4
+
5
+ module RSpec::Matchers
6
+ include AktionTest::Matchers::FileSystem
7
+ end
@@ -1,3 +1,3 @@
1
1
  module AktionTest
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/aktion_test.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require "aktion_test/version"
2
+ require "aktion_test/matchers/base"
3
+ require "aktion_test/matchers/integrations/rspec"
2
4
 
3
- module AktionTest
4
- # Your code goes here...
5
- end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe AktionTest::Matchers::FileSystem::DirectoryExistanceMatcher do
4
+ it "accepts an existing directory" do
5
+ File.expand_path(File.join(__FILE__, '..')).should be_a_directory
6
+ end
7
+
8
+ it "does not accept a non-existant directory" do
9
+ File.expand_path(File.join(__FILE__, '..', 'foo')).should_not be_a_directory
10
+ end
11
+
12
+ it "does not accept a file" do
13
+ __FILE__.should_not be_a_directory
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe AktionTest::Matchers::FileSystem::FileExistanceMatcher do
4
+ it "should accept an existing file" do
5
+ __FILE__.should be_a_file
6
+ end
7
+
8
+ it "should not accept a non-existant file" do
9
+ File.join(__FILE__, '..', 'foo').should_not be_a_file
10
+ end
11
+
12
+ it "should not accept a directory" do
13
+ File.join(__FILE__, '..').should_not be_a_file
14
+ end
15
+ end
@@ -0,0 +1,233 @@
1
+ require 'spec_helper'
2
+ require 'active_support/core_ext/string'
3
+
4
+ describe AktionTest::Matchers::FileSystem::DirectoryContentMatcher do
5
+ let(:test_root) { File.expand_path(File.join(__FILE__, '..', '..', 'tmp')) }
6
+
7
+ before(:each) do
8
+ FileUtils.rm_rf(test_root) if Dir.exists?(test_root)
9
+ end
10
+
11
+ def build(structure, root=test_root)
12
+ FileUtils.mkdir(root) unless Dir.exists?(root)
13
+
14
+ structure.each do |entry|
15
+ case entry
16
+ when String
17
+ FileUtils.touch("#{root}/#{entry}")
18
+ when Hash
19
+ entry.each{|k,v| build(v, "#{root}/#{k}")}
20
+ end
21
+ end
22
+ end
23
+
24
+ def matcher(*args)
25
+ @matcher ||= described_class.new(*args)
26
+ end
27
+
28
+ context "single file in the root" do
29
+ it "will accept if the file exists" do
30
+ build(['test_file'])
31
+ test_root.should have_tree(['test_file'])
32
+ end
33
+
34
+ it "will not accept if the file does not exist" do
35
+ test_root.should_not have_tree(['test_file'])
36
+ end
37
+
38
+ it "will not accept if the file is in a subdirectory" do
39
+ build([{'a' => ['test_file']}])
40
+ test_root.should_not have_tree(['test_file'])
41
+ end
42
+ end
43
+
44
+ context "single file in a specific directory" do
45
+ it "will accept if the file exists in the subdirectory" do
46
+ build([{'a' => ['test_file']}])
47
+ test_root.should have_tree([{'a' => ['test_file']}])
48
+ end
49
+
50
+ it "will not accept if the file does not exist" do
51
+ test_root.should_not have_tree([{'a' => ['test_file']}])
52
+ end
53
+
54
+ it "will not accept if the file exists in the root" do
55
+ build(['test_file'])
56
+ test_root.should_not have_tree([{'a' => ['test_file']}])
57
+ end
58
+
59
+ it "will not accept if the file exists in another directory" do
60
+ build([{'b' => ['test_file']}])
61
+ test_root.should_not have_tree([{'a' => ['test_file']}])
62
+ end
63
+ end
64
+
65
+ context "single file in a specific tree" do
66
+ let(:tree) { [{'a' => [{'b' => [{'c' => ['test_file']}]}]}] }
67
+ it "will accept if the file exists in the tree" do
68
+ build(tree)
69
+ test_root.should have_tree(tree)
70
+ end
71
+ end
72
+
73
+ context "single file in any subdirectory" do
74
+ let(:tree) { [{'*' => ['test_file']}]}
75
+
76
+ it "will accept if the file exists in a subdirectory" do
77
+ build([{'a' => ['test_file']}])
78
+ test_root.should have_tree(tree)
79
+ end
80
+
81
+ it "will not accept if the file exists deeper in the tree" do
82
+ build([{'a' => [{'b' => ['test_file']}]}])
83
+ test_root.should_not have_tree(tree)
84
+ end
85
+ end
86
+
87
+ context "single file in any tree" do
88
+ let(:tree) { [{'**' => ['test_file']}]}
89
+
90
+ it "will accept if the file exists in the tree" do
91
+ build([{'a' => [{'b' => [{'c' => ['test_file']}]}]}])
92
+ test_root.should have_tree(tree)
93
+ end
94
+ end
95
+
96
+ context "single file with mixed specific and any directory" do
97
+ let(:tree) { [{'a' => [{'*' => [{'c' => ['test_file']}]}]}]}
98
+
99
+ it "will accept if the file exists in search path" do
100
+ build([{'a' => [{'b' => [{'c' => ['test_file']}]}]}])
101
+ test_root.should have_tree(tree)
102
+ end
103
+
104
+ it "will not accept if the file exists outside the search path" do
105
+ build([{
106
+ 'a' => [{
107
+ 'c' => ['test_file'],
108
+ 'b' => [{
109
+ 'd' => [{
110
+ 'c' => ['test_file']
111
+ }]
112
+ }]
113
+ }]
114
+ }])
115
+ test_root.should_not have_tree(tree)
116
+ end
117
+ end
118
+
119
+ context "single file with mixed specific directories and any tree" do
120
+ let(:tree) { [{'a' => [{'**' => [{'d' => ['test_file']}]}]}]}
121
+
122
+ it "will accept if the file exists in the search path" do
123
+ build([{'a' => [{'b' => [{'c' => [{'d' => ['test_file']}]}]}]}])
124
+ test_root.should have_tree(tree)
125
+ end
126
+
127
+ it "will not accept if the file is outside the search path" do
128
+ build([{'a' => [{'b' => [{'c' => ['test_file']}]}]}])
129
+ test_root.should_not have_tree(tree)
130
+ end
131
+ end
132
+
133
+ context "multiple files in the root directory" do
134
+ let(:tree) { %w(test_file_a test_file_b) }
135
+
136
+ it "will accept if all of the files exist" do
137
+ build(%w(test_file_a test_file_b))
138
+ test_root.should have_tree(tree)
139
+ end
140
+
141
+ it "will not accept if not all of the files exist" do
142
+ build(['test_file_a'])
143
+ test_root.should_not have_tree(tree)
144
+ end
145
+ end
146
+
147
+ context "multiple files a subdirectory" do
148
+ let(:tree) { [{'a' => %w(test_file_a test_file_b)}]}
149
+
150
+ it "will accept if all of the files exist" do
151
+ build(tree)
152
+ test_root.should have_tree(tree)
153
+ end
154
+
155
+ it "will not accept if not all of the files exist" do
156
+ build([{'a' => %w(test_file_a)}])
157
+ test_root.should_not have_tree(tree)
158
+ end
159
+ end
160
+
161
+ context "multiple files in multiple subdirectories" do
162
+ let(:tree) { [{'a' => %w(test_file_a test_file_b), 'b' => %w(test_file_a test_file_b)}]}
163
+
164
+ it "will accept if all of the files exist" do
165
+ build(tree)
166
+ test_root.should have_tree(tree)
167
+ end
168
+
169
+ it "will not accept if not all of the files exist" do
170
+ build([{'a' => %w(test_file_a test_file_b), 'b' => %w(test_file_b)}])
171
+ test_root.should_not have_tree(tree)
172
+ end
173
+ end
174
+
175
+ context "when files do not exist" do
176
+ it "lists the missing files" do
177
+ #build([{'a' => ['test_file_a', {'b' => [{'c' => ['test_file_b', 'test_file_c']}]}]}])
178
+ build([{'a' => ['test_file_a']}])
179
+ matcher(['test_file', {'a' => ['test_file_a', {'b' => [{'c' => ['test_file_b', 'test_file_c']}]}]}]).matches?(test_root)
180
+ matcher.failure_message.should == <<-FAIL.strip_heredoc.strip
181
+ Expected #{test_root} to contain:
182
+ test_file
183
+ a/
184
+ test_file_a
185
+ b/
186
+ c/
187
+ test_file_b
188
+ test_file_c
189
+
190
+ test_file was not found
191
+ a/b/c/test_file_b was not found
192
+ a/b/c/test_file_c was not found
193
+ FAIL
194
+ end
195
+ end
196
+
197
+ context "when the subject does not exist" do
198
+ let(:nx_root) { File.join(test_root, 'a') }
199
+
200
+ it "will not be accepeted" do
201
+ nx_root.should_not have_file('some_file')
202
+ end
203
+
204
+ it "specifies the problem as the subject not existing" do
205
+ matcher(['some_file']).matches?(nx_root)
206
+ matcher.failure_message.should == <<-FAIL.strip_heredoc.strip
207
+ Expected #{nx_root} to contain:
208
+ some_file
209
+
210
+ #{nx_root} does not exist.
211
+ FAIL
212
+ end
213
+ end
214
+
215
+ context "when the subject is not a directory" do
216
+ before(:each) { build(['test_file']) }
217
+
218
+ it "will not be accepted" do
219
+ File.join(test_root, 'test_file').should_not have_file('some_file')
220
+ end
221
+
222
+ it "specifies the problem as the subject not being a directory" do
223
+ bad_root = File.join(test_root, 'test_file')
224
+ matcher(['some_file']).matches?(bad_root)
225
+ matcher.failure_message.should == <<-FAIL.strip_heredoc.strip
226
+ Expected #{bad_root} to contain:
227
+ some_file
228
+
229
+ #{bad_root} is not a directory.
230
+ FAIL
231
+ end
232
+ end
233
+ end
@@ -0,0 +1,7 @@
1
+ require 'aktion_test'
2
+
3
+ RSpec.configure do |config|
4
+ config.treat_symbols_as_metadata_keys_with_true_values = true
5
+ config.run_all_when_everything_filtered = true
6
+ config.order = 'random'
7
+ end
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.0.2
4
+ version: 0.1.0
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-23 00:00:00.000000000 Z
12
+ date: 2012-11-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -100,16 +100,29 @@ extensions: []
100
100
  extra_rdoc_files: []
101
101
  files:
102
102
  - .gitignore
103
+ - .rspec
103
104
  - .rvmrc
105
+ - .travis.yml
106
+ - CHANGELOG.md
104
107
  - Gemfile
105
108
  - LICENSE
106
109
  - README.md
107
110
  - Rakefile
108
111
  - aktion_test.gemspec
109
112
  - lib/aktion_test.rb
113
+ - lib/aktion_test/matchers/base.rb
114
+ - lib/aktion_test/matchers/file_system/be_a_directory.rb
115
+ - lib/aktion_test/matchers/file_system/be_a_file.rb
116
+ - lib/aktion_test/matchers/file_system/directory_contains.rb
117
+ - lib/aktion_test/matchers/integrations/rspec.rb
110
118
  - lib/aktion_test/version.rb
119
+ - spec/matchers/be_a_directory_spec.rb
120
+ - spec/matchers/be_a_file_spec.rb
121
+ - spec/matchers/directory_contains_spec.rb
122
+ - spec/spec_helper.rb
111
123
  homepage: http://aktionlab.com
112
- licenses: []
124
+ licenses:
125
+ - MIT
113
126
  post_install_message:
114
127
  rdoc_options: []
115
128
  require_paths:
@@ -117,9 +130,9 @@ require_paths:
117
130
  required_ruby_version: !ruby/object:Gem::Requirement
118
131
  none: false
119
132
  requirements:
120
- - - ! '>='
133
+ - - ~>
121
134
  - !ruby/object:Gem::Version
122
- version: '0'
135
+ version: 1.9.2
123
136
  required_rubygems_version: !ruby/object:Gem::Requirement
124
137
  none: false
125
138
  requirements:
@@ -132,4 +145,8 @@ rubygems_version: 1.8.24
132
145
  signing_key:
133
146
  specification_version: 3
134
147
  summary: Gems, libs, helpers for test suites.
135
- test_files: []
148
+ test_files:
149
+ - spec/matchers/be_a_directory_spec.rb
150
+ - spec/matchers/be_a_file_spec.rb
151
+ - spec/matchers/directory_contains_spec.rb
152
+ - spec/spec_helper.rb