expectations 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -0,0 +1,64 @@
1
+ = expectations
2
+
3
+ expectations is a lightweight unit testing framework. Tests (expectations) can be written as follows
4
+
5
+ expect 2 do
6
+ 1 + 1
7
+ end
8
+
9
+ expect NoMethodError do
10
+ Object.invalid_method_call
11
+ end.
12
+
13
+ expectations is designed to encourage unit testing best practices such as
14
+ - discourage setting more than one expectation at a time
15
+ - promote maintainability by not providing a setup or teardown method
16
+ - provide one syntax for setting up state based or behavior based expectation
17
+ - focus on readability by providing no mechanism for describing an expectation other than the code in the expectation.
18
+
19
+ Mocking is done utilizing Mocha
20
+
21
+ by Jay[http://blog.jayfields.com] Fields[http://blog.jayfields.com]
22
+
23
+ == Download and Installation
24
+
25
+ You can download arbs from here[http://rubyforge.org/projects/expectations] or install it with the following command.
26
+
27
+ $ gem install expectations
28
+
29
+ == License
30
+
31
+ You may use, copy and redistribute this library under the same terms as Ruby itself (see http://www.ruby-lang.org/en/LICENSE.txt).
32
+
33
+ == Usage
34
+
35
+ expectations can be used for state based and behavior based testing.
36
+
37
+ require File.dirname(__FILE__) + "/test_helper"
38
+
39
+ Expectations do
40
+
41
+ # State based expectation where a value equals another value
42
+ expect 2 do
43
+ 1 + 1
44
+ end
45
+
46
+ # State based expectation where an exception is expected. Simply expect the Class of the intended exception
47
+ expect NoMethodError do
48
+ Object.no_method
49
+ end
50
+
51
+ # Behavior based test using a traditional mock
52
+ expect mock.to_receive(:dial).with("2125551212").times(2) do |phone|
53
+ phone.dial("2125551212")
54
+ phone.dial("2125551212")
55
+ end
56
+
57
+ # Behavior based test on a concrete mock
58
+ expect Object.to_receive(:deal).with(1) do
59
+ Object.deal(1)
60
+ end
61
+
62
+ end
63
+
64
+ == Contributors
@@ -28,9 +28,9 @@ class Expectations::SuiteResults
28
28
  end
29
29
 
30
30
  def print_results(benchmark)
31
- benchmark_seconds = benchmark.real.to_s.split(".").first
32
- benchmark_subseconds = benchmark.real.to_s.split(".").last[0..5]
33
- out.puts "\nFinished in #{benchmark_seconds}.#{benchmark_subseconds} seconds"
31
+ run_time = benchmark.real
32
+ run_time = 0.001 if run_time < 0.001
33
+ out.puts "\nFinished in #{run_time.to_s.gsub(/(\d*)\.(\d{0,5}).*/,'\1.\2')} seconds"
34
34
  if result
35
35
  out.puts "\nSuccess: #{fulfilled.size} fulfilled"
36
36
  else
data/rakefile.rb CHANGED
@@ -16,8 +16,16 @@ Rake::RDocTask.new do |task|
16
16
  task.rdoc_files.include('README', 'lib/**/*.rb')
17
17
  end
18
18
 
19
+ task :rdoc => :readme
20
+
21
+ desc "Generate README"
22
+ task :readme do
23
+ %x[erb README_TEMPLATE > README]
24
+ end
25
+
26
+
19
27
  desc "Upload RDoc to RubyForge"
20
- task :publish_rdoc => [:rdoc] do
28
+ task :publish_rdoc => :rdoc do
21
29
  Rake::SshDirPublisher.new("jaycfields@rubyforge.org", "/var/www/gforge-projects/expectations", "doc").upload
22
30
  end
23
31
 
@@ -33,7 +41,7 @@ specification = Gem::Specification.new do |s|
33
41
  expect NoMethodError do
34
42
  Object.invalid_method_call
35
43
  end."
36
- s.version = "0.0.2"
44
+ s.version = "0.0.3"
37
45
  s.author = 'Jay Fields'
38
46
  s.description = "A lightweight unit testing framework. Tests (expectations) will be written as follows
39
47
  expect 2 do
@@ -50,7 +58,7 @@ specification = Gem::Specification.new do |s|
50
58
  s.extra_rdoc_files = ['README']
51
59
  s.rdoc_options << '--title' << 'expectations' << '--main' << 'README' << '--line-numbers'
52
60
 
53
- s.autorequire = 'expectations'
61
+ s.email = 'ruby@jayfields.com'
54
62
  s.files = FileList['{lib,test}/**/*.rb', '[A-Z]*$', 'rakefile.rb'].to_a
55
63
  s.test_file = "test/all_tests.rb"
56
64
  end
@@ -0,0 +1,26 @@
1
+ require File.dirname(__FILE__) + "/test_helper"
2
+
3
+ Expectations do
4
+
5
+ # State based expectation where a value equals another value
6
+ expect 2 do
7
+ 1 + 1
8
+ end
9
+
10
+ # State based expectation where an exception is expected. Simply expect the Class of the intended exception
11
+ expect NoMethodError do
12
+ Object.no_method
13
+ end
14
+
15
+ # Behavior based test using a traditional mock
16
+ expect mock.to_receive(:dial).with("2125551212").times(2) do |phone|
17
+ phone.dial("2125551212")
18
+ phone.dial("2125551212")
19
+ end
20
+
21
+ # Behavior based test on a concrete mock
22
+ expect Object.to_receive(:deal).with(1) do
23
+ Object.deal(1)
24
+ end
25
+
26
+ end
metadata CHANGED
@@ -1,20 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: expectations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jay Fields
8
- autorequire: expectations
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2007-12-25 00:00:00 -05:00
12
+ date: 2007-12-27 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
16
  description: A lightweight unit testing framework. Tests (expectations) will be written as follows expect 2 do 1 + 1 end expect NoMethodError do Object.invalid_method_call end.
17
- email:
17
+ email: ruby@jayfields.com
18
18
  executables: []
19
19
 
20
20
  extensions: []
@@ -35,7 +35,7 @@ files:
35
35
  - test/expectations/results_test.rb
36
36
  - test/expectations/suite_results_test.rb
37
37
  - test/expectations/suite_test.rb
38
- - test/sample_expecations_test.rb
38
+ - test/sample_expectations_test.rb
39
39
  - test/silent.rb
40
40
  - test/test_helper.rb
41
41
  - rakefile.rb
@@ -1,34 +0,0 @@
1
- require File.dirname(__FILE__) + "/test_helper"
2
-
3
- class Phone
4
- end
5
-
6
- Expectations do
7
-
8
- expect 2 do
9
- 1 + 1
10
- end
11
-
12
- expect NoMethodError do
13
- Object.no_method
14
- end
15
-
16
- expect mock.to_receive(:redial) do |phone|
17
- phone.redial(10)
18
- end
19
-
20
- expect mock.to_receive(:dial).with("2125551212") do |phone|
21
- phone.dial("2125551212")
22
- end
23
-
24
- expect mock.to_receive(:dial).times(2) do |phone|
25
- phone.dial
26
- phone.dial
27
- end
28
-
29
- expect Object.to_receive(:foo).with(1).times(2) do
30
- Object.foo(1)
31
- Object.foo(1)
32
- end
33
-
34
- end