aktion_test 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc CHANGED
@@ -6,7 +6,7 @@
6
6
  # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
7
7
  # Only full ruby name is supported here, for short names use:
8
8
  # echo "rvm use 1.9.3" > .rvmrc
9
- environment_id="ruby-1.9.3-p194@aktion_test"
9
+ environment_id="ruby-1.9.3-p327@aktion_test"
10
10
 
11
11
  # Uncomment the following lines if you want to verify rvm version per project
12
12
  # rvmrc_rvm_version="1.15.6 (stable)" # 1.10.1 seams as a safe start
data/.travis.yml CHANGED
@@ -1,6 +1,8 @@
1
1
  rvm:
2
2
  - 1.9.2
3
3
  - 1.9.3
4
+ - jruby-19mode
5
+ - rbx-19mode
4
6
 
5
7
  script: "bundle exec rake"
6
8
 
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # v0.2.0
2
+ * Build out a better base matcher class
3
+ * Implement a SpecHelper loading interface
4
+ * Modularize components that can be loaded via SpecHelper
5
+
1
6
  # v0.1.2
2
7
  * Add a file contents matcher
3
8
 
@@ -1,12 +1,44 @@
1
1
  module AktionTest
2
2
  module Matchers
3
3
  class Base
4
+ def initialize
5
+ @matches = nil
6
+ end
7
+
8
+ def matches?(subject)
9
+ return @matches unless @matches.nil?
10
+ @subject = subject
11
+ @matches = !!perform_match!
12
+ end
13
+
4
14
  def failure_message
5
- "Expected #{expectation}\n#{problem}"
15
+ raise "Called failure message before determining a match from #{caller[0]}" if @matches.nil?
16
+ raise "Called failure message while the match was positive from #{caller[0]}" if @matches
17
+ "Expected #{expectation}\n#{problems_for_should}\n"
6
18
  end
7
19
 
8
20
  def negative_failure_message
9
- "Did not expect #{expectation}"
21
+ raise "Called negative failure message before determining a match from #{caller[0]}" if @matches.nil?
22
+ raise "Called negative failure message while the match was unsucessful from #{caller[0]}" unless @matches
23
+ "Did not expect #{expectation}\n#{problems_for_should_not}\n"
24
+ end
25
+
26
+ protected
27
+
28
+ def expectation
29
+ "Override expectation to provide expectation details"
30
+ end
31
+
32
+ def problems_for_should
33
+ "Override problem_for_should to set problems in the failure message output."
34
+ end
35
+
36
+ def problems_for_should_not
37
+ "Override problem_for_should_not to set problems in the failure message output."
38
+ end
39
+
40
+ def perform_match!
41
+ raise "Override perform_match! with your custom matching logic. The subject is available through @subject"
10
42
  end
11
43
  end
12
44
  end
@@ -1,98 +1,102 @@
1
1
  module AktionTest
2
2
  module Matchers
3
3
  module FileSystem
4
- def have_file(path)
5
- segments = path.split('/')
6
- file = segments.pop
7
- tree = segments.reverse.reduce([file]) {|a,b| [{b => a}] }
8
- have_tree(tree)
9
- end
10
-
11
- def have_tree(tree)
12
- DirectoryContentMatcher.new(tree)
13
- end
14
-
15
- class DirectoryContentMatcher < Matchers::Base
16
- def initialize(tree)
17
- @tree = tree
4
+ module DirectoryContains
5
+ def have_file(path)
6
+ segments = path.split('/')
7
+ file = segments.pop
8
+ tree = segments.reverse.reduce([file]) {|a,b| [{b => a}] }
9
+ have_tree(tree)
18
10
  end
19
11
 
20
- def matches?(subject)
21
- @subject = subject
22
- directory_exists? && matches_tree?(@tree)
12
+ def have_tree(tree)
13
+ Matcher.new(tree)
23
14
  end
24
15
 
25
- protected
16
+ class Matcher < Matchers::Base
17
+ def initialize(tree)
18
+ @tree = tree
19
+ end
20
+
21
+ protected
22
+
23
+ def perform_match!
24
+ directory_exists? && matches_tree?(@tree)
25
+ end
26
26
 
27
- def matches_tree?(tree, directory='')
28
- tree.all? do |entry|
29
- if entry.is_a? String
30
- Dir[File.join(@subject, directory, entry)].any?
31
- elsif entry.is_a? Hash
32
- entry.to_a.all?{|dir,subtree| matches_tree?(subtree, File.join(directory, dir))}
27
+ def matches_tree?(tree, directory='')
28
+ tree.all? do |entry|
29
+ if entry.is_a? String
30
+ Dir[File.join(@subject, directory, entry)].any?
31
+ elsif entry.is_a? Hash
32
+ entry.to_a.all?{|dir,subtree| matches_tree?(subtree, File.join(directory, dir))}
33
+ end
33
34
  end
34
35
  end
35
- end
36
36
 
37
- def directory_exists?
38
- Dir.exists?(@subject)
39
- end
37
+ def directory_exists?
38
+ Dir.exists?(@subject)
39
+ end
40
40
 
41
- def expectation
42
- "#{@subject} to contain:\n#{print_tree}\n"
43
- end
41
+ def expectation
42
+ "#{@subject} to contain:\n#{print_tree}\n"
43
+ end
44
44
 
45
- def flatten_tree(structure, directory='')
46
- structure.map do |entry|
47
- case entry
48
- when Hash
49
- entry.map{|dir,entries| flatten_tree(entries, "#{directory}#{dir}/")}
50
- when String
51
- "#{directory}#{entry}"
52
- end
53
- end.flatten
54
- end
45
+ def flatten_tree(structure, directory='')
46
+ structure.map do |entry|
47
+ case entry
48
+ when Hash
49
+ entry.map{|dir,entries| flatten_tree(entries, "#{directory}#{dir}/")}
50
+ when String
51
+ "#{directory}#{entry}"
52
+ end
53
+ end.flatten
54
+ end
55
55
 
56
- def problem
57
- unless directory_exists?
58
- if File.exists? @subject
59
- "#{@subject} is not a directory."
60
- else
61
- "#{@subject} does not exist."
62
- end
63
- else
64
- missing_files = flatten_tree(@tree).reject do |path|
65
- Dir["#{@subject}/#{path}"].any?
66
- end
67
- if missing_files.any?
68
- missing_files.map{|f| "#{f} was not found"}.join("\n")
56
+ def problems_for_should
57
+ unless directory_exists?
58
+ if File.exists? @subject
59
+ "#{@subject} is not a directory."
60
+ else
61
+ "#{@subject} does not exist."
62
+ end
69
63
  else
70
- "Unknown Problem"
64
+ missing_files = flatten_tree(@tree).reject do |path|
65
+ Dir["#{@subject}/#{path}"].any?
66
+ end
67
+ if missing_files.any?
68
+ missing_files.map{|f| "#{f} was not found"}.join("\n")
69
+ else
70
+ "Unknown Problem"
71
+ end
71
72
  end
72
73
  end
73
- end
74
74
 
75
- def print_tree(tree=nil, depth=1)
76
- tree ||= @tree
77
- tree.map do |entry|
78
- case entry
79
- when String then
80
- print_file(entry, depth)
81
- when Hash
82
- entry.map do |k,v|
83
- print_directory(k, depth) + "\n" +
84
- print_tree(v, depth + 1)
85
- end.join("\n")
86
- end
87
- end.join("\n")
88
- end
75
+ def problems_for_should_not
76
+ end
89
77
 
90
- def print_file(file, depth)
91
- "#{" " * depth}#{file}"
92
- end
78
+ def print_tree(tree=nil, depth=1)
79
+ tree ||= @tree
80
+ tree.map do |entry|
81
+ case entry
82
+ when String then
83
+ print_file(entry, depth)
84
+ when Hash
85
+ entry.map do |k,v|
86
+ print_directory(k, depth) + "\n" +
87
+ print_tree(v, depth + 1)
88
+ end.join("\n")
89
+ end
90
+ end.join("\n")
91
+ end
93
92
 
94
- def print_directory(directory, depth)
95
- print_file(directory + '/', depth)
93
+ def print_file(file, depth)
94
+ "#{" " * depth}#{file}"
95
+ end
96
+
97
+ def print_directory(directory, depth)
98
+ print_file(directory + '/', depth)
99
+ end
96
100
  end
97
101
  end
98
102
  end
@@ -0,0 +1,46 @@
1
+ module AktionTest
2
+ module Matchers
3
+ module FileSystem
4
+ module DirectoryExistance
5
+ def be_a_directory
6
+ Matcher.new
7
+ end
8
+
9
+ class Matcher < Matchers::Base
10
+ def initialize
11
+ super
12
+ end
13
+
14
+ protected
15
+
16
+ def perform_match!
17
+ directory_exists?
18
+ end
19
+
20
+ def expectation
21
+ "#{@subject} to be a directory."
22
+ end
23
+
24
+ def problems_for_should
25
+ if File.exists? @subject
26
+ unless File.directory? @subject
27
+ "#{@subject} is not a directory."
28
+ else
29
+ "Unknown"
30
+ end
31
+ else
32
+ "#{@subject} does not exist."
33
+ end
34
+ end
35
+
36
+ def problems_for_should_not
37
+ end
38
+
39
+ def directory_exists?
40
+ Dir.exists? @subject
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -1,108 +1,109 @@
1
1
  module AktionTest
2
2
  module Matchers
3
3
  module FileSystem
4
- def match_lines(lines, options={})
5
- FileContentMatcher.new(lines, options)
6
- end
7
-
8
- class FileContentMatcher < Matchers::Base
9
- def initialize(lines, options={})
10
- @original_lines = lines
11
- @lines, @options = init_lines(lines), options
12
- @options[:match_method] = :all
13
- allow_any if @options.delete(:allow_any)
14
- sequentially if @options.delete(:sequentially)
15
- @options[:after] = regexp(@options[:after]) unless @options[:after].nil?
16
- @options[:before] = regexp(@options[:before]) unless @options[:before].nil?
4
+ module FileContains
5
+ def match_lines(lines, options={})
6
+ Matcher.new(lines, options)
17
7
  end
18
8
 
19
- def init_lines(lines)
20
- lines.map { |line| regexp(line) }.flatten
21
- end
9
+ class Matcher < Matchers::Base
10
+ def initialize(lines, options={})
11
+ @original_lines = lines
12
+ @lines, @options = init_lines(lines), options
13
+ @options[:match_method] = :all
14
+ allow_any if @options.delete(:allow_any)
15
+ sequentially if @options.delete(:sequentially)
16
+ @options[:after] = regexp(@options[:after]) unless @options[:after].nil?
17
+ @options[:before] = regexp(@options[:before]) unless @options[:before].nil?
18
+ end
22
19
 
23
- def matches?(file)
24
- @file = file
25
- file_exists? && file_has_contents?
26
- end
27
-
28
- def allow_any
29
- @options[:match_method] = :any
30
- self
31
- end
20
+ def init_lines(lines)
21
+ lines.map { |line| regexp(line) }.flatten
22
+ end
32
23
 
33
- def after(match_after)
34
- @options[:after] = regexp(match_after)
35
- self
36
- end
24
+ def allow_any
25
+ @options[:match_method] = :any
26
+ self
27
+ end
37
28
 
38
- def before(match_before)
39
- @options[:before] = regexp(match_before)
40
- self
41
- end
29
+ def after(match_after)
30
+ @options[:after] = regexp(match_after)
31
+ self
32
+ end
42
33
 
43
- def sequentially
44
- @options[:match_method] = :sequence
45
- self
46
- end
34
+ def before(match_before)
35
+ @options[:before] = regexp(match_before)
36
+ self
37
+ end
47
38
 
48
- protected
49
-
50
- def expectation
51
- "#{@file} to have contents:\n---\n#{print_lines}\n---"
52
- end
39
+ def sequentially
40
+ @options[:match_method] = :sequence
41
+ self
42
+ end
53
43
 
54
- def print_lines
55
- @original_lines.join("\n")
56
- end
44
+ protected
45
+
46
+ def expectation
47
+ "#{@subject} to have contents:\n---\n#{print_lines}\n---"
48
+ end
49
+
50
+ def perform_match!
51
+ file_exists? && file_has_contents?
52
+ end
53
+
54
+ def print_lines
55
+ @original_lines.join("\n")
56
+ end
57
57
 
58
- def problem
59
- if File.exists?(@file)
60
- if File.directory?(@file)
61
- "#{@file} is a directory."
58
+ def problems_for_should
59
+ if File.exists?(@subject)
60
+ if File.directory?(@subject)
61
+ "#{@subject} is a directory."
62
+ else
63
+ "Unknown Problem"
64
+ end
62
65
  else
63
- "Unknown Problem"
66
+ "#{@subject} does not exist."
64
67
  end
65
- else
66
- "#{@file} does not exist."
67
68
  end
68
- end
69
69
 
70
- def file_exists?
71
- File.exists?(@file) && !File.directory?(@file)
72
- end
70
+ def file_exists?
71
+ File.exists?(@subject) && !File.directory?(@subject)
72
+ end
73
73
 
74
- def file_has_contents?
75
- find = -> lines, match { lines.find_index{|line| line =~ match} }
76
- scope = -> lines, scope, default { find[lines, @options[scope]] || default }
77
- lines = -> lines { lines.take(scope[lines, :before, lines.count]).drop(scope[lines, :after, -1] + 1) }
74
+ def file_has_contents?
75
+ find = -> lines, match { lines.find_index{|line| line =~ match} }
76
+ scope = -> lines, scope, default { find[lines, @options[scope]] || default }
77
+ lines = -> lines { lines.take(scope[lines, :before, lines.count]).drop(scope[lines, :after, -1] + 1) }
78
78
 
79
79
 
80
- match_method[@lines.map{|line| find[lines[open(@file).readlines], line]}]
81
- end
80
+ match_method[@lines.map{|line| find[lines[open(@subject).readlines], line]}]
81
+ end
82
82
 
83
- def match_method
84
- case @options[:match_method]
85
- when :sequence
86
- -> result { !result.first.nil? && (result == ((result.first)..(result.first + @lines.count - 1)).to_a) }
87
- when :any
88
- -> result { !result.all?(&:nil?) }
89
- when :all
90
- -> result { result.none?(&:nil?) }
83
+ def match_method
84
+ case @options[:match_method]
85
+ when :sequence
86
+ -> result { !result.first.nil? && (result == ((result.first)..(result.first + @lines.count - 1)).to_a) }
87
+ when :any
88
+ -> result { !result.all?(&:nil?) }
89
+ when :all
90
+ -> result { result.none?(&:nil?) }
91
+ end
91
92
  end
92
- end
93
93
 
94
- def regexp(object)
95
- case object
96
- when Regexp then object
97
- when Array then object.map {|item| regexp(item)}
98
- when String
99
- if object.include? "\n"
100
- object.split("\n").map{|item| %r(^#{item}$)}
94
+ def regexp(object)
95
+ case object
96
+ when Regexp then object
97
+ when Array then object.map {|item| regexp(item)}
98
+ when String
99
+ if object.include? "\n"
100
+ object.split("\n").map{|item| %r(^#{item}$)}
101
+ else
102
+ %r(^#{object}$)
103
+ end
101
104
  else
102
- %r(^#{object}$)
105
+ %r(^#{object.to_s}$)
103
106
  end
104
- else
105
- %r(^#{object.to_s}$)
106
107
  end
107
108
  end
108
109
  end
@@ -0,0 +1,51 @@
1
+ module AktionTest
2
+ module Matchers
3
+ module FileSystem
4
+ module FileExistance
5
+ def be_a_file
6
+ Matcher.new
7
+ end
8
+
9
+ class Matcher < Matchers::Base
10
+ def initialize
11
+ super
12
+ end
13
+
14
+ protected
15
+
16
+ def perform_match!
17
+ file_exists? and file_is_not_a_directory?
18
+ end
19
+
20
+ def expectation
21
+ "#{@subject} to be a file."
22
+ end
23
+
24
+ def problems_for_should
25
+ if File.exists?(@subject)
26
+ if File.directory?(@subject)
27
+ "#{@subject} is a directory."
28
+ else
29
+ "Unknown"
30
+ end
31
+ else
32
+ "#{@subject} does not exist."
33
+ end
34
+ end
35
+
36
+ def problems_for_should_not
37
+ end
38
+
39
+ def file_exists?
40
+ File.exists? @subject
41
+ end
42
+
43
+ def file_is_not_a_directory?
44
+ !File.directory? @subject
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+
@@ -0,0 +1,19 @@
1
+ module AktionTest
2
+ module Module
3
+ module AktionTest
4
+ extend ActiveSupport::Concern
5
+
6
+ included do |spec_helper|
7
+ require 'aktion_test/matchers/base'
8
+
9
+ ::RSpec.configure do |config|
10
+ config.include Support::ClassBuilder
11
+ config.include Matchers::FileSystem::DirectoryExistance
12
+ config.include Matchers::FileSystem::FileExistance
13
+ config.include Matchers::FileSystem::DirectoryContains
14
+ config.include Matchers::FileSystem::FileContains
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ module AktionTest
2
+ module Module
3
+ module RSpec
4
+ extend ActiveSupport::Concern
5
+
6
+ included do |spec_helper|
7
+ ::RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.order = 'random'
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ module AktionTest
2
+ module Module
3
+ module Simplecov
4
+ require 'simplecov'
5
+ ::SimpleCov.start
6
+ end
7
+ end
8
+ end
9
+
@@ -0,0 +1,42 @@
1
+ require 'singleton'
2
+
3
+ module AktionTest
4
+ class SpecHelper
5
+ include Singleton
6
+
7
+ attr_accessor :modules
8
+
9
+ class << self
10
+ include ActiveSupport::Callbacks
11
+ define_callbacks :load
12
+
13
+ def load(*modules)
14
+ load_constants(modules)
15
+
16
+ instance.modules.each do |mod|
17
+ include mod
18
+ end
19
+
20
+ puts "Loaded #{modules.map(&:to_s).join(', ')}"
21
+ end
22
+
23
+ private
24
+
25
+ def load_constants(modules)
26
+ modules.each do |mod|
27
+ module_name = "AktionTest::Module::#{mod}"
28
+ begin
29
+ module_const = module_name.constantize
30
+ instance.modules << module_const
31
+ rescue NameError
32
+ puts "Unknown module #{mod}."
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ def initialize
39
+ @modules = []
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,29 @@
1
+ module AktionTest
2
+ module Support
3
+ module ClassBuilder
4
+ def self.included(example_group)
5
+ example_group.class_eval do
6
+ after do
7
+ teardown_defined_constants
8
+ end
9
+ end
10
+ end
11
+
12
+ def define_class(class_name, base = Object, &block)
13
+ class_name = class_name.to_s.camelize
14
+
15
+ Class.new(base).tap do |constant_class|
16
+ Object.const_set(class_name, constant_class)
17
+ constant_class.unloadable
18
+ constant_class.class_eval(&block) if block_given?
19
+ constant_class.reset_column_information if constant_class.respond_to? :reset_column_information
20
+ end
21
+ end
22
+
23
+ def teardown_defined_constants
24
+ ActiveSupport::Dependencies.clear
25
+ end
26
+ end
27
+ end
28
+ end
29
+
@@ -1,3 +1,3 @@
1
1
  module AktionTest
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/aktion_test.rb CHANGED
@@ -1,7 +1,34 @@
1
+ require "aktion_test/version"
1
2
  require 'active_support/dependencies'
3
+ require 'active_support/core_ext'
2
4
 
3
- require "aktion_test/version"
4
- require "aktion_test/matchers/base"
5
- require 'aktion_test/class_builder'
6
- require "aktion_test/matchers/integrations/rspec"
5
+ module AktionTest
6
+ extend ActiveSupport::Autoload
7
+
8
+ autoload :SpecHelper
9
+
10
+ module Module
11
+ extend ActiveSupport::Autoload
12
+
13
+ autoload :AktionTest
14
+ autoload :RSpec, 'aktion_test/module/rspec'
15
+ autoload :Simplecov
16
+ end
17
+
18
+ module Matchers
19
+ module FileSystem
20
+ extend ActiveSupport::Autoload
21
+
22
+ autoload :DirectoryContains
23
+ autoload :DirectoryExistance
24
+ autoload :FileContains
25
+ autoload :FileExistance
26
+ end
27
+ end
28
+
29
+ module Support
30
+ extend ActiveSupport::Autoload
7
31
 
32
+ autoload :ClassBuilder
33
+ end
34
+ end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe AktionTest::ClassBuilder do
3
+ describe AktionTest::Support::ClassBuilder do
4
4
  it "creates a new class" do
5
5
  clazz = define_class('Foo')
6
6
  clazz.new.should be_a Foo
@@ -1,51 +1,59 @@
1
1
  require 'spec_helper'
2
2
 
3
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'/)
4
+ before :each do
5
+ matcher_class = define_class('Matcher', described_class) do
6
+ def expectation; "an expectation"; end
7
+ def problems_for_should; "\na problem\nanother problem"; end
8
+ def problems_for_should_not; "\na problem\nanother problem"; end
9
+ end
10
+
11
+ @matcher = matcher_class.new
8
12
  end
13
+
14
+ describe '#failure_message' do
15
+ it "outputs an expectation with associated problems when the matcher is unsuccessful" do
16
+ @matcher.stub(:perform_match! => false)
17
+ @matcher.matches?(nil)
18
+ @matcher.failure_message.should == <<-MSG.strip_heredoc
19
+ Expected an expectation
20
+
21
+ a problem
22
+ another problem
23
+ MSG
24
+ end
9
25
 
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
26
+ it "raises an error if called before running the matcher" do
27
+ expect { @matcher.failure_message }.to raise_error(RuntimeError, /failure message before/)
16
28
  end
17
29
 
18
- expect { matcher.new.failure_message }.to raise_error(NameError, /`problem'/)
30
+ it "raises an error if called when the matcher was successful" do
31
+ @matcher.stub(:perform_match! => true)
32
+ @matcher.matches? nil
33
+ expect { @matcher.failure_message }.to raise_error(RuntimeError, /failure message while/)
34
+ end
19
35
  end
20
36
 
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
37
+ describe '#negative_failure_message' do
38
+ before { @matcher.stub(:perform_match! => true) }
39
+ it 'outputs a negative expectation with associated problems when the matcher is successful' do
40
+ @matcher.matches?(nil)
41
+ @matcher.negative_failure_message.should == <<-MSG.strip_heredoc
42
+ Did not expect an expectation
27
43
 
28
- def problem
29
- 'A Problem'
30
- end
44
+ a problem
45
+ another problem
46
+ MSG
31
47
  end
32
48
 
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
49
+ it "raises an error if called before running the matcher" do
50
+ expect { @matcher.negative_failure_message }.to raise_error(RuntimeError, /negative failure message before/)
45
51
  end
46
52
 
47
- matcher.new.negative_failure_message.should == <<-MSG.strip_heredoc.strip
48
- Did not expect an expectation
49
- MSG
53
+ it "raises an error if called when the matcher was unsuccessful" do
54
+ @matcher.stub(:perform_match! => false)
55
+ @matcher.matches? nil
56
+ expect { @matcher.negative_failure_message }.to raise_error(RuntimeError, /negative failure message while/)
57
+ end
50
58
  end
51
59
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'active_support/core_ext/string'
3
3
 
4
- describe AktionTest::Matchers::FileSystem::DirectoryContentMatcher do
4
+ describe AktionTest::Matchers::FileSystem::DirectoryContains::Matcher do
5
5
  let(:test_root) { File.expand_path(File.join(__FILE__, '..', '..', 'tmp')) }
6
6
 
7
7
  before(:each) do
@@ -33,18 +33,8 @@ describe AktionTest::Matchers::FileSystem::DirectoryContentMatcher do
33
33
  matcher.negative_failure_message.should == <<-MSG.strip_heredoc
34
34
  Did not expect #{test_root} to contain:
35
35
  test_file
36
- MSG
37
- end
38
36
 
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
37
 
47
- Unknown Problem
48
38
  MSG
49
39
  end
50
40
  end
@@ -201,7 +191,7 @@ describe AktionTest::Matchers::FileSystem::DirectoryContentMatcher do
201
191
  #build([{'a' => ['test_file_a', {'b' => [{'c' => ['test_file_b', 'test_file_c']}]}]}])
202
192
  build([{'a' => ['test_file_a']}])
203
193
  matcher(['test_file', {'a' => ['test_file_a', {'b' => [{'c' => ['test_file_b', 'test_file_c']}]}]}]).matches?(test_root)
204
- matcher.failure_message.should == <<-FAIL.strip_heredoc.strip
194
+ matcher.failure_message.should == <<-FAIL.strip_heredoc
205
195
  Expected #{test_root} to contain:
206
196
  test_file
207
197
  a/
@@ -227,7 +217,7 @@ describe AktionTest::Matchers::FileSystem::DirectoryContentMatcher do
227
217
 
228
218
  it "specifies the problem as the subject not existing" do
229
219
  matcher(['some_file']).matches?(nx_root)
230
- matcher.failure_message.should == <<-FAIL.strip_heredoc.strip
220
+ matcher.failure_message.should == <<-FAIL.strip_heredoc
231
221
  Expected #{nx_root} to contain:
232
222
  some_file
233
223
 
@@ -246,7 +236,7 @@ describe AktionTest::Matchers::FileSystem::DirectoryContentMatcher do
246
236
  it "specifies the problem as the subject not being a directory" do
247
237
  bad_root = File.join(test_root, 'test_file')
248
238
  matcher(['some_file']).matches?(bad_root)
249
- matcher.failure_message.should == <<-FAIL.strip_heredoc.strip
239
+ matcher.failure_message.should == <<-FAIL.strip_heredoc
250
240
  Expected #{bad_root} to contain:
251
241
  some_file
252
242
 
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe AktionTest::Matchers::FileSystem::DirectoryExistanceMatcher do
3
+ describe AktionTest::Matchers::FileSystem::DirectoryExistance::Matcher do
4
4
  context "an existing directory" do
5
5
  let(:dir) { File.expand_path(File.join(__FILE__, '..')) }
6
6
 
@@ -11,17 +11,9 @@ describe AktionTest::Matchers::FileSystem::DirectoryExistanceMatcher do
11
11
  it "provides a negative failure message" do
12
12
  matcher = described_class.new
13
13
  matcher.matches?(dir)
14
- matcher.negative_failure_message.should == <<-MSG.strip_heredoc.strip
14
+ matcher.negative_failure_message.should == <<-MSG.strip_heredoc
15
15
  Did not expect #{dir} to be a directory.
16
- MSG
17
- end
18
16
 
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
17
  MSG
26
18
  end
27
19
  end
@@ -36,7 +28,7 @@ describe AktionTest::Matchers::FileSystem::DirectoryExistanceMatcher do
36
28
  it "explains that the subject does not exist" do
37
29
  matcher = described_class.new
38
30
  matcher.matches?(dir)
39
- matcher.failure_message.should == <<-MSG.strip_heredoc.strip
31
+ matcher.failure_message.should == <<-MSG.strip_heredoc
40
32
  Expected #{dir} to be a directory.
41
33
  #{dir} does not exist.
42
34
  MSG
@@ -53,7 +45,7 @@ describe AktionTest::Matchers::FileSystem::DirectoryExistanceMatcher do
53
45
  it "explains that the subject is a file" do
54
46
  matcher = described_class.new
55
47
  matcher.matches?(dir)
56
- matcher.failure_message.should == <<-MSG.strip_heredoc.strip
48
+ matcher.failure_message.should == <<-MSG.strip_heredoc
57
49
  Expected #{dir} to be a directory.
58
50
  #{dir} is not a directory.
59
51
  MSG
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe AktionTest::Matchers::FileSystem::FileContentMatcher do
3
+ describe AktionTest::Matchers::FileSystem::FileContains::Matcher do
4
4
  def create_file(file='tmp/test_file', &block)
5
5
  FileUtils.mkdir('tmp') unless Dir.exists? 'tmp'
6
6
  File.open(file, 'w') {|f| f << yield }
@@ -18,7 +18,7 @@ describe AktionTest::Matchers::FileSystem::FileContentMatcher do
18
18
  it 'explains that the file was not found' do
19
19
  matcher = described_class.new(['anything'])
20
20
  matcher.matches?('tmp/test_file')
21
- matcher.failure_message.should == <<-MSG.strip_heredoc.strip
21
+ matcher.failure_message.should == <<-MSG.strip_heredoc
22
22
  Expected tmp/test_file to have contents:
23
23
  ---
24
24
  anything
@@ -36,7 +36,7 @@ describe AktionTest::Matchers::FileSystem::FileContentMatcher do
36
36
  it 'explains that the file is a directory' do
37
37
  matcher = described_class.new(['anything'])
38
38
  matcher.matches?(File.dirname(__FILE__))
39
- matcher.failure_message.should == <<-MSG.strip_heredoc.strip
39
+ matcher.failure_message.should == <<-MSG.strip_heredoc
40
40
  Expected #{File.dirname(__FILE__)} to have contents:
41
41
  ---
42
42
  anything
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe AktionTest::Matchers::FileSystem::FileExistanceMatcher do
3
+ describe AktionTest::Matchers::FileSystem::FileExistance::Matcher do
4
4
  context "an existing file" do
5
5
  let(:file) { __FILE__ }
6
6
 
@@ -11,17 +11,9 @@ describe AktionTest::Matchers::FileSystem::FileExistanceMatcher do
11
11
  it "provides a negative failure message" do
12
12
  matcher = described_class.new
13
13
  matcher.matches?(file)
14
- matcher.negative_failure_message.should == <<-MSG.strip_heredoc.strip
14
+ matcher.negative_failure_message.should == <<-MSG.strip_heredoc
15
15
  Did not expect #{file} to be a file.
16
- MSG
17
- end
18
16
 
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
17
  MSG
26
18
  end
27
19
  end
@@ -36,7 +28,7 @@ describe AktionTest::Matchers::FileSystem::FileExistanceMatcher do
36
28
  it "explains that the subject does not exist" do
37
29
  matcher = described_class.new
38
30
  matcher.matches?(file)
39
- matcher.failure_message.should == <<-MSG.strip_heredoc.strip
31
+ matcher.failure_message.should == <<-MSG.strip_heredoc
40
32
  Expected #{file} to be a file.
41
33
  #{file} does not exist.
42
34
  MSG
@@ -53,7 +45,7 @@ describe AktionTest::Matchers::FileSystem::FileExistanceMatcher do
53
45
  it "explains that the subject is a directory" do
54
46
  matcher = described_class.new
55
47
  matcher.matches?(file)
56
- matcher.failure_message.should == <<-MSG.strip_heredoc.strip
48
+ matcher.failure_message.should == <<-MSG.strip_heredoc
57
49
  Expected #{file} to be a file.
58
50
  #{file} is a directory.
59
51
  MSG
data/spec/spec_helper.rb CHANGED
@@ -1,16 +1,3 @@
1
- require 'simplecov'
2
-
3
- SimpleCov.start do
4
- add_filter '/spec/'
5
- refuse_coverage_drop
6
- minimum_coverage 95
7
- end
8
-
9
- require 'active_support/core_ext/string'
10
1
  require 'aktion_test'
11
2
 
12
- RSpec.configure do |config|
13
- config.treat_symbols_as_metadata_keys_with_true_values = true
14
- config.run_all_when_everything_filtered = true
15
- config.order = 'random'
16
- end
3
+ AktionTest::SpecHelper.load :Simplecov, :RSpec, :AktionTest
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.2
4
+ version: 0.2.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-29 00:00:00.000000000 Z
12
+ date: 2013-01-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -110,20 +110,23 @@ files:
110
110
  - Rakefile
111
111
  - aktion_test.gemspec
112
112
  - lib/aktion_test.rb
113
- - lib/aktion_test/class_builder.rb
114
113
  - lib/aktion_test/matchers/base.rb
115
- - lib/aktion_test/matchers/file_system/be_a_directory.rb
116
- - lib/aktion_test/matchers/file_system/be_a_file.rb
117
114
  - lib/aktion_test/matchers/file_system/directory_contains.rb
115
+ - lib/aktion_test/matchers/file_system/directory_existance.rb
118
116
  - lib/aktion_test/matchers/file_system/file_contains.rb
119
- - lib/aktion_test/matchers/integrations/rspec.rb
117
+ - lib/aktion_test/matchers/file_system/file_existance.rb
118
+ - lib/aktion_test/module/aktion_test.rb
119
+ - lib/aktion_test/module/rspec.rb
120
+ - lib/aktion_test/module/simplecov.rb
121
+ - lib/aktion_test/spec_helper.rb
122
+ - lib/aktion_test/support/class_builder.rb
120
123
  - lib/aktion_test/version.rb
121
124
  - spec/aktion_test/class_builder_spec.rb
122
125
  - spec/matchers/base_spec.rb
123
- - spec/matchers/be_a_directory_spec.rb
124
- - spec/matchers/be_a_file_spec.rb
125
126
  - spec/matchers/directory_contains_spec.rb
127
+ - spec/matchers/directory_existance_spec.rb
126
128
  - spec/matchers/file_contains_spec.rb
129
+ - spec/matchers/file_existance_spec.rb
127
130
  - spec/spec_helper.rb
128
131
  homepage: http://aktionlab.com
129
132
  licenses:
@@ -144,6 +147,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
147
  - - ! '>='
145
148
  - !ruby/object:Gem::Version
146
149
  version: '0'
150
+ segments:
151
+ - 0
152
+ hash: -214091085
147
153
  requirements: []
148
154
  rubyforge_project:
149
155
  rubygems_version: 1.8.24
@@ -153,8 +159,8 @@ summary: Gems, libs, helpers for test suites.
153
159
  test_files:
154
160
  - spec/aktion_test/class_builder_spec.rb
155
161
  - spec/matchers/base_spec.rb
156
- - spec/matchers/be_a_directory_spec.rb
157
- - spec/matchers/be_a_file_spec.rb
158
162
  - spec/matchers/directory_contains_spec.rb
163
+ - spec/matchers/directory_existance_spec.rb
159
164
  - spec/matchers/file_contains_spec.rb
165
+ - spec/matchers/file_existance_spec.rb
160
166
  - spec/spec_helper.rb
@@ -1,31 +0,0 @@
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
-
@@ -1,41 +0,0 @@
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
- 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
33
- end
34
-
35
- def directory_exists?
36
- Dir.exists? @subject
37
- end
38
- end
39
- end
40
- end
41
- end
@@ -1,46 +0,0 @@
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? and file_is_not_a_directory?
15
- end
16
-
17
- protected
18
-
19
- def expectation
20
- "#{@subject} to be a file."
21
- end
22
-
23
- def problem
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
41
- end
42
- end
43
- end
44
- end
45
- end
46
-
@@ -1,8 +0,0 @@
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
- require 'aktion_test/matchers/file_system/file_contains'
5
-
6
- module RSpec::Matchers
7
- include AktionTest::Matchers::FileSystem
8
- end