attest 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/Gemfile +1 -1
  2. data/Gemfile.lock +6 -1
  3. data/README.rdoc +121 -36
  4. data/Rakefile +12 -1
  5. data/VERSION +1 -1
  6. data/attest.gemspec +61 -36
  7. data/bin/attest +18 -24
  8. data/doodle.txt +73 -29
  9. data/examples/{magic_calculator.rb → basic_functionality_example.rb} +42 -8
  10. data/examples/mocha_example.rb +43 -0
  11. data/examples/module_example.rb +49 -0
  12. data/examples/more/{placeholder.rb → multiple_context_example.rb} +0 -0
  13. data/examples/more/nesting/expectations_as_tests_example.rb +20 -0
  14. data/lib/attest.rb +4 -20
  15. data/lib/attest/config.rb +3 -6
  16. data/lib/attest/core_ext/kernel.rb +19 -1
  17. data/lib/attest/core_ext/object.rb +1 -2
  18. data/lib/attest/core_ext/proc.rb +35 -0
  19. data/lib/attest/execution_context.rb +156 -50
  20. data/lib/attest/expectation_result.rb +22 -1
  21. data/lib/attest/interface/output_writer_configurator.rb +25 -0
  22. data/lib/attest/interface/possible_tests_configurator.rb +35 -0
  23. data/lib/attest/interface/test_double_configurator.rb +40 -0
  24. data/lib/attest/output/basic_output_writer.rb +14 -46
  25. data/lib/attest/output/failures_only_output_writer.rb +47 -0
  26. data/lib/attest/output/output_writer.rb +124 -0
  27. data/lib/attest/output/output_writer_interface.rb +24 -0
  28. data/lib/attest/output/test_unit_output_writer.rb +32 -0
  29. data/lib/attest/proc/proc_source_reader.rb +49 -0
  30. data/lib/attest/rake/attesttask.rb +38 -0
  31. data/lib/attest/test_container.rb +15 -4
  32. data/lib/attest/test_loader.rb +28 -0
  33. data/lib/attest/test_object.rb +35 -29
  34. data/lib/attest/test_parser.rb +69 -11
  35. data/lib/trollop.rb +782 -0
  36. data/spec/interface/output_writer_configurator_test.rb +18 -0
  37. data/spec/interface/possible_tests_configurator_test.rb +55 -0
  38. data/spec/interface/test_double_configurator_test.rb +20 -0
  39. data/spec/output/output_writer_test.rb +20 -0
  40. data/spec/tmp/new_require_test.rb +10 -0
  41. metadata +55 -18
  42. data/.gitignore +0 -23
  43. data/examples/standard_calculator.rb +0 -28
  44. data/lib/attest/attest_error.rb +0 -7
  45. data/lib/attest/itself.rb +0 -34
@@ -0,0 +1,18 @@
1
+ require 'attest/interface/output_writer_configurator'
2
+
3
+ this_tests "output writer configuration" do
4
+ test("should use the default when output writer identifier is nil") do
5
+ should_be_true{ OutputWriterConfigurator.configure(nil).class == OutputWriterConfigurator.configure(OutputWriterConfigurator.default_output_writer_identifier).class}
6
+ end
7
+
8
+ test("should raise an error when output writer identifier doesn't match any of the known ones") do
9
+ should_raise {OutputWriterConfigurator.configure("unknown identifier")}
10
+ end
11
+
12
+ test("should not raise an error when output writer identifier is one of the known ones") do
13
+ identifiers = OutputWriterConfigurator.output_writer_identifiers
14
+ identifiers.each do |identifier|
15
+ should_not_raise{OutputWriterConfigurator.configure(identifier)}
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,55 @@
1
+ require 'attest/interface/possible_tests_configurator'
2
+ require 'fakefs/safe'
3
+
4
+ this_tests "possible tests configurator" do
5
+
6
+ before_all do
7
+ FakeFS.activate!
8
+ FakeFS::FileSystem.clear
9
+ @base_test_path = "/path/to/tests"
10
+ @sub_test_dir_name = "sub_test_dir"
11
+ @sub_test_dir_path = "#{@base_test_path}/#{@sub_test_dir_name}"
12
+ @test_file_names = ["file1.rb","file2.rb","file3.rb"]
13
+ @test_file1_path = "#{@base_test_path}/#{@test_file_names[0]}"
14
+ @test_file2_path = "#{@sub_test_dir_path}/#{@test_file_names[1]}"
15
+ @test_file3_path = "#{@sub_test_dir_path}/#{@test_file_names[2]}"
16
+ FileUtils.mkdir_p(@base_test_path)
17
+ FileUtils.mkdir_p(@sub_test_dir_path)
18
+ File.open(@test_file1_path, 'w') {|f| f.write("require 'pp'")}
19
+ File.open(@test_file2_path, 'w') {|f| f.write("require 'pp'")}
20
+ File.open(@test_file3_path, 'w') {|f| f.write("require 'pp'")}
21
+ end
22
+
23
+ after_all do
24
+ FakeFS.deactivate!
25
+ end
26
+
27
+ test("raises exception if no included test locations") do
28
+ should_raise {PossibleTestsConfigurator.configure(nil)}
29
+ end
30
+
31
+ test("should return one location when single file is passed in") do
32
+ included_locations = [@test_file1_path]
33
+ actual_included_location = PossibleTestsConfigurator.configure(included_locations)
34
+ should_equal([@test_file1_path], actual_included_location)
35
+ end
36
+
37
+ test("should return two locations when directory with two files is passed in") do
38
+ included_locations = [@sub_test_dir_path]
39
+ actual_included_locations = PossibleTestsConfigurator.configure(included_locations)
40
+ should_equal([@test_file2_path, @test_file3_path], actual_included_locations)
41
+ end
42
+
43
+ test("should return three locations when single file and dir with two files is passed in") do
44
+ included_locations = [@sub_test_dir_path, @test_file1_path]
45
+ actual_included_locations = PossibleTestsConfigurator.configure(included_locations)
46
+ should_equal([@test_file2_path, @test_file3_path, @test_file1_path], actual_included_locations)
47
+ end
48
+
49
+ test("should return two locations passing in one file and one dir with 2 files one of which is excluded") do
50
+ included_locations = [@sub_test_dir_path, @test_file1_path]
51
+ excluded_locations = [@test_file2_path]
52
+ actual_included_locations = PossibleTestsConfigurator.configure(included_locations, excluded_locations)
53
+ should_equal([@test_file3_path, @test_file1_path], actual_included_locations)
54
+ end
55
+ end
@@ -0,0 +1,20 @@
1
+ require 'attest/interface/test_double_configurator'
2
+
3
+ this_tests "test double configuration" do
4
+ test("should use default when nil test double identifier") do
5
+ actual_test_double_identifier = TestDoubleConfigurator.configure(nil)
6
+ should_equal(TestDoubleConfigurator.default_test_double_identifier, actual_test_double_identifier)
7
+ end
8
+
9
+ test("should raise an error when non-existant test double identifier") do
10
+ should_raise{TestDoubleConfigurator.configure("non-existant")}
11
+ end
12
+
13
+ test("should call configuration method when real test double identifer used") do
14
+ TestDoubleConfigurator.test_double_identifiers.each do |double_identifer|
15
+ configure_method_name = :"configure_#{double_identifer}"
16
+ TestDoubleConfigurator.expects(configure_method_name)
17
+ TestDoubleConfigurator.configure(double_identifer)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ require 'attest/output/output_writer'
2
+
3
+ this_tests "output writer base class" do
4
+ before_each {@output_writer = Attest::Output::OutputWriter.new}
5
+ test("should format as milliseconds when elapsed time is less than 1 second") do
6
+ should_equal("12 milliseconds", @output_writer.elapsed_time(0.012, 0))
7
+ end
8
+ test("should format as seconds when elapsed time less than 60 seconds") do
9
+ should_equal("1.3 seconds", @output_writer.elapsed_time(1.3, 0))
10
+ should_equal("22.05 seconds", @output_writer.elapsed_time(22.06, 0.01))
11
+ end
12
+ test("should format as minutes and seconds when elapsed time is less than 1 hour but more than 1 minute") do
13
+ should_equal("1 minutes, 22.05 seconds", @output_writer.elapsed_time(82.06, 0.01))
14
+ should_equal("59 minutes, 22.05 seconds", @output_writer.elapsed_time(3562.06, 0.01))
15
+ end
16
+ test("should format as hours, minutes and seconds when elapsed time is over an hour") do
17
+ should_equal("1 hours, 0 minutes, 0 seconds", @output_writer.elapsed_time(3600.01, 0.01))
18
+ should_equal("1 hours, 59 minutes, 22.05 seconds", @output_writer.elapsed_time(7162.06, 0.01))
19
+ end
20
+ end
@@ -0,0 +1,10 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../examples/basic_functionality_example")
2
+ require File.expand_path(File.dirname(__FILE__) + "/../examples/module_example")
3
+
4
+ if ENV["attest"]
5
+ this_tests "test from required files should not be executed when this file is loaded" do
6
+ test("it just passes"){should_be_true{true}}
7
+ end
8
+ end
9
+
10
+ #TODO need to figure out a way to make this a proper test
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attest
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alan Skorkin
@@ -15,12 +15,11 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-29 00:00:00 +11:00
18
+ date: 2010-12-21 00:00:00 +11:00
19
19
  default_executable: attest
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- name: trollop
23
- prerelease: false
22
+ name: mocha
24
23
  requirement: &id001 !ruby/object:Gem::Requirement
25
24
  none: false
26
25
  requirements:
@@ -30,8 +29,23 @@ dependencies:
30
29
  segments:
31
30
  - 0
32
31
  version: "0"
33
- type: :runtime
32
+ type: :development
33
+ prerelease: false
34
34
  version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: fakefs
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :development
47
+ prerelease: false
48
+ version_requirements: *id002
35
49
  description: Attest allows you to define spec-like tests inline (within the same file as your actual code) which means almost non-existant overheads to putting some tests around your code. It also tries to not be too prescriptive regarding the 'right' way to test. You want to test private methods - go ahead, access unexposed instance variables - no worries, pending and disabled tests are first class citizens. Don't like the output format, use a different one or write your own. Infact you don't even have to define you tests inline if you prefer the 'traditional' way, separate directory and all. You should be allowed to test your code the way you want to, not the way someone else says you have to!
36
50
  email: alan@skorks.com
37
51
  executables:
@@ -43,7 +57,6 @@ extra_rdoc_files:
43
57
  - README.rdoc
44
58
  files:
45
59
  - .document
46
- - .gitignore
47
60
  - Gemfile
48
61
  - Gemfile.lock
49
62
  - LICENSE
@@ -53,28 +66,45 @@ files:
53
66
  - attest.gemspec
54
67
  - bin/attest
55
68
  - doodle.txt
56
- - examples/magic_calculator.rb
57
- - examples/more/placeholder.rb
58
- - examples/standard_calculator.rb
69
+ - examples/basic_functionality_example.rb
70
+ - examples/mocha_example.rb
71
+ - examples/module_example.rb
72
+ - examples/more/multiple_context_example.rb
73
+ - examples/more/nesting/expectations_as_tests_example.rb
59
74
  - lib/attest.rb
60
- - lib/attest/attest_error.rb
61
75
  - lib/attest/config.rb
62
76
  - lib/attest/core_ext/kernel.rb
63
77
  - lib/attest/core_ext/object.rb
78
+ - lib/attest/core_ext/proc.rb
64
79
  - lib/attest/execution_context.rb
65
80
  - lib/attest/expectation_result.rb
66
- - lib/attest/itself.rb
81
+ - lib/attest/interface/output_writer_configurator.rb
82
+ - lib/attest/interface/possible_tests_configurator.rb
83
+ - lib/attest/interface/test_double_configurator.rb
67
84
  - lib/attest/output/basic_output_writer.rb
85
+ - lib/attest/output/failures_only_output_writer.rb
86
+ - lib/attest/output/output_writer.rb
87
+ - lib/attest/output/output_writer_interface.rb
88
+ - lib/attest/output/test_unit_output_writer.rb
89
+ - lib/attest/proc/proc_source_reader.rb
90
+ - lib/attest/rake/attesttask.rb
68
91
  - lib/attest/test_container.rb
92
+ - lib/attest/test_loader.rb
69
93
  - lib/attest/test_object.rb
70
94
  - lib/attest/test_parser.rb
95
+ - lib/trollop.rb
96
+ - spec/interface/output_writer_configurator_test.rb
97
+ - spec/interface/possible_tests_configurator_test.rb
98
+ - spec/interface/test_double_configurator_test.rb
99
+ - spec/output/output_writer_test.rb
100
+ - spec/tmp/new_require_test.rb
71
101
  has_rdoc: true
72
102
  homepage: http://github.com/skorks/attest
73
103
  licenses: []
74
104
 
75
105
  post_install_message:
76
- rdoc_options:
77
- - --charset=UTF-8
106
+ rdoc_options: []
107
+
78
108
  require_paths:
79
109
  - lib
80
110
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -103,6 +133,13 @@ signing_key:
103
133
  specification_version: 3
104
134
  summary: An inline unit testing/spec framework that doesn't force you to follow arbitrary rules
105
135
  test_files:
106
- - examples/more/placeholder.rb
107
- - examples/magic_calculator.rb
108
- - examples/standard_calculator.rb
136
+ - examples/basic_functionality_example.rb
137
+ - examples/mocha_example.rb
138
+ - examples/module_example.rb
139
+ - examples/more/multiple_context_example.rb
140
+ - examples/more/nesting/expectations_as_tests_example.rb
141
+ - spec/interface/output_writer_configurator_test.rb
142
+ - spec/interface/possible_tests_configurator_test.rb
143
+ - spec/interface/test_double_configurator_test.rb
144
+ - spec/output/output_writer_test.rb
145
+ - spec/tmp/new_require_test.rb
data/.gitignore DELETED
@@ -1,23 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
-
21
- ## PROJECT::SPECIFIC
22
- vendor
23
- .bundle
@@ -1,28 +0,0 @@
1
- class StandardCalculator
2
- def self.plus(x, y)
3
- x + y
4
- end
5
-
6
- def self.minus(x, y)
7
- x - y
8
- end
9
- end
10
-
11
- module CalcMethods
12
- def double(x)
13
- 2 * x
14
- end
15
- end
16
-
17
- if ENV["attest"]
18
- this_tests "another class with claculations" do
19
- test("adding two numbers") {should_be_true{StandardCalculator.plus(5,11) == 16}}
20
- test("subtracting two numbers"){should_not_be_true{StandardCalculator.minus(10,5) == 4}}
21
- end
22
-
23
- this_tests CalcMethods do
24
- before_all { @module_class = create_and_include(CalcMethods) }
25
-
26
- test("magically instance of a class that will include the module"){should_be_true{@module_class.double(5)==10}}
27
- end
28
- end
@@ -1,7 +0,0 @@
1
- module Attest
2
- class AttestError < RuntimeError
3
- def initialize(message)
4
- super message
5
- end
6
- end
7
- end
@@ -1,34 +0,0 @@
1
- module Attest
2
- class Itself
3
-
4
- def initialize(object)
5
- @itself = object
6
- @state = state
7
- end
8
-
9
- #when error is set, if it is a child of an exception or is an exception itself then with_message is available, otherwise it is not and shoudl throw a no method
10
-
11
- #def with_message(regex)
12
- #raise NoMethodError if !@itself.kind_of?(Exception)
13
- #if @itself.message =~ regex
14
- #@state = Attest::Itself.STATES[:success]
15
- #end
16
- #end
17
-
18
- #def should_equal(another_object)
19
- #@itself == another_object
20
- #end
21
-
22
- #def should_not_equal(another_object)
23
- #@itself != another_object
24
- #end
25
-
26
- #should_be_true
27
- #should_not_be_true
28
- #should_equal
29
- #should_not_equal
30
- #should_be_same
31
- #should_not_be_same
32
- #with_message if itself is an error object
33
- end
34
- end