rspec 0.7.3 → 0.7.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +23 -1
- data/Rakefile +11 -9
- data/bin/spec +0 -1
- data/lib/spec.rb +1 -0
- data/lib/spec/callback.rb +3 -0
- data/lib/spec/callback/callback_container.rb +60 -0
- data/lib/spec/callback/extensions/module.rb +24 -0
- data/lib/spec/callback/extensions/object.rb +33 -0
- data/lib/spec/expectations/diff.rb +10 -14
- data/lib/spec/expectations/extensions.rb +1 -3
- data/lib/spec/expectations/extensions/numeric.rb +6 -1
- data/lib/spec/expectations/extensions/object.rb +72 -18
- data/lib/spec/expectations/should/base.rb +27 -5
- data/lib/spec/expectations/should/have.rb +2 -2
- data/lib/spec/expectations/should/should.rb +5 -4
- data/lib/spec/mocks/error_generator.rb +23 -12
- data/lib/spec/mocks/message_expectation.rb +4 -0
- data/lib/spec/mocks/mock_handler.rb +9 -8
- data/lib/spec/rake/spectask.rb +2 -1
- data/lib/spec/runner.rb +0 -1
- data/lib/spec/runner/backtrace_tweaker.rb +1 -0
- data/lib/spec/runner/context_eval.rb +1 -1
- data/lib/spec/runner/formatter/base_text_formatter.rb +1 -1
- data/lib/spec/runner/formatter/html_formatter.rb +94 -74
- data/lib/spec/runner/option_parser.rb +5 -1
- data/lib/spec/runner/specification.rb +64 -37
- data/lib/spec/version.rb +3 -3
- data/vendor/{selenium → web_spec/selenium}/README.txt +0 -0
- data/vendor/{selenium → web_spec/selenium}/find_rspecs_home_page.rb +0 -0
- data/vendor/{selenium → web_spec/selenium}/rspec_selenium.rb +0 -0
- data/vendor/{selenium → web_spec/selenium}/start_browser_once.patch +0 -0
- data/vendor/{watir → web_spec/watir}/README.txt +2 -2
- data/vendor/web_spec/watir/find_rspecs_home_page.rb +27 -0
- data/vendor/{watir → web_spec/watir}/find_rspecs_home_page.txt +0 -0
- data/vendor/{watir → web_spec/watir}/rspec_watir.rb +13 -12
- data/vendor/web_spec/web_test_html_formatter.rb +8 -0
- data/vendor/web_spec/web_test_html_formatter_helper.rb +26 -0
- data/vendor/web_spec/web_test_html_formatter_osx_helper.rb +19 -0
- data/vendor/web_spec/web_test_html_formatter_win_helper.rb +14 -0
- metadata +19 -14
- data/lib/spec/expectations/extensions/inspect_for_expectation_not_met_error.rb +0 -15
- data/lib/spec/expectations/extensions/symbol.rb +0 -5
- data/lib/spec/runner/extensions/object.rb +0 -21
- data/vendor/watir/find_rspecs_home_page.rb +0 -21
@@ -74,7 +74,11 @@ module Spec
|
|
74
74
|
opts.on("-s", "--spec SPECIFICATION_NAME", "Execute context or specification with matching name") do |spec_name|
|
75
75
|
options.spec_name = spec_name
|
76
76
|
end
|
77
|
-
|
77
|
+
|
78
|
+
opts.on("-o", "--out OUTPUT_FILE", "Path to output file (defaults to STDOUT)") do |outfile|
|
79
|
+
options.out = File.new(outfile, 'w')
|
80
|
+
end
|
81
|
+
|
78
82
|
opts.on("-l", "--line LINE_NUMBER", Integer, "Execute context or specification at given line") do |line_number|
|
79
83
|
options.line_number = line_number.to_i
|
80
84
|
end
|
@@ -1,68 +1,95 @@
|
|
1
1
|
module Spec
|
2
2
|
module Runner
|
3
3
|
class Specification
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
module ClassMethods
|
5
|
+
attr_accessor :current
|
6
|
+
protected :current=
|
7
|
+
|
8
|
+
callback_events :before_setup, :after_teardown
|
9
9
|
end
|
10
|
-
|
10
|
+
extend ClassMethods
|
11
|
+
|
12
|
+
attr_reader :command
|
13
|
+
callback_events :before_setup, :after_teardown
|
14
|
+
|
11
15
|
def initialize(name, opts={}, &block)
|
12
16
|
@from = caller(0)[3]
|
13
17
|
@name = name
|
14
18
|
@options = opts
|
15
|
-
@
|
16
|
-
@listeners = []
|
19
|
+
@command = block
|
17
20
|
end
|
18
21
|
|
19
22
|
def run(reporter, setup_block, teardown_block, dry_run, execution_context)
|
20
|
-
reporter.spec_started(@name)
|
23
|
+
reporter.spec_started(@name) if reporter
|
21
24
|
return reporter.spec_finished(@name) if dry_run
|
22
|
-
@@current_spec = self
|
23
|
-
errors = []
|
24
|
-
begin
|
25
|
-
execution_context.instance_exec(&setup_block) unless setup_block.nil?
|
26
|
-
setup_ok = true
|
27
|
-
execution_context.instance_exec(&@block)
|
28
|
-
spec_ok = true
|
29
|
-
rescue => e
|
30
|
-
errors << e
|
31
|
-
end
|
32
25
|
|
26
|
+
errors = []
|
33
27
|
begin
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
errors
|
28
|
+
set_current
|
29
|
+
setup_ok = setup_spec(execution_context, errors, &setup_block)
|
30
|
+
spec_ok = execute_spec(execution_context, errors) if setup_ok
|
31
|
+
teardown_ok = teardown_spec(execution_context, errors, &teardown_block)
|
38
32
|
ensure
|
39
|
-
|
40
|
-
@@current_spec = nil
|
33
|
+
clear_current
|
41
34
|
end
|
42
35
|
|
43
36
|
SpecShouldRaiseHandler.new(@from, @options).handle(errors)
|
44
|
-
reporter.spec_finished(@name, errors.first, failure_location(setup_ok, spec_ok, teardown_ok))
|
37
|
+
reporter.spec_finished(@name, errors.first, failure_location(setup_ok, spec_ok, teardown_ok)) if reporter
|
45
38
|
end
|
46
39
|
|
47
40
|
def matches_matcher?(matcher)
|
48
41
|
matcher.matches? @name
|
49
42
|
end
|
50
43
|
|
51
|
-
|
52
|
-
|
44
|
+
private
|
45
|
+
def setup_spec(execution_context, errors, &setup_block)
|
46
|
+
notify_before_setup(errors)
|
47
|
+
execution_context.instance_eval(&setup_block) if setup_block
|
48
|
+
return errors.empty?
|
49
|
+
rescue => e
|
50
|
+
errors << e
|
51
|
+
return false
|
53
52
|
end
|
54
53
|
|
55
|
-
def
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
54
|
+
def execute_spec(execution_context, errors)
|
55
|
+
execution_context.instance_eval(&command)
|
56
|
+
return true
|
57
|
+
rescue => e
|
58
|
+
errors << e
|
59
|
+
return false
|
60
|
+
end
|
61
|
+
|
62
|
+
def teardown_spec(execution_context, errors, &teardown_block)
|
63
|
+
execution_context.instance_eval(&teardown_block) if teardown_block
|
64
|
+
notify_after_teardown(errors)
|
65
|
+
return errors.empty?
|
66
|
+
rescue => e
|
67
|
+
errors << e
|
68
|
+
return false
|
69
|
+
end
|
70
|
+
|
71
|
+
def notify_before_setup(errors)
|
72
|
+
self.class.send(:notify_callbacks, :before_setup, self, &append_errors(errors))
|
73
|
+
notify_callbacks(:before_setup, self, &append_errors(errors))
|
74
|
+
end
|
75
|
+
|
76
|
+
def notify_after_teardown(errors)
|
77
|
+
notify_callbacks(:after_teardown, self, &append_errors(errors))
|
78
|
+
self.class.send(:notify_callbacks, :after_teardown, self, &append_errors(errors))
|
79
|
+
end
|
80
|
+
|
81
|
+
def append_errors(errors)
|
82
|
+
proc {|error| errors << error}
|
83
|
+
end
|
84
|
+
|
85
|
+
def set_current
|
86
|
+
self.class.send(:current=, self)
|
87
|
+
end
|
88
|
+
|
89
|
+
def clear_current
|
90
|
+
self.class.send(:current=, nil)
|
63
91
|
end
|
64
92
|
|
65
|
-
private
|
66
93
|
def failure_location(setup_ok, spec_ok, teardown_ok)
|
67
94
|
return 'setup' unless setup_ok
|
68
95
|
return @name unless spec_ok
|
data/lib/spec/version.rb
CHANGED
@@ -3,9 +3,9 @@ module Spec
|
|
3
3
|
unless defined? MAJOR
|
4
4
|
MAJOR = 0
|
5
5
|
MINOR = 7
|
6
|
-
TINY =
|
7
|
-
# RANDOM_TOKEN: 0.
|
8
|
-
REV = "$LastChangedRevision:
|
6
|
+
TINY = 4
|
7
|
+
# RANDOM_TOKEN: 0.644898830762263
|
8
|
+
REV = "$LastChangedRevision: 1201 $".match(/LastChangedRevision: (\d+)/)[1]
|
9
9
|
|
10
10
|
STRING = [MAJOR, MINOR, TINY].join('.')
|
11
11
|
FULL_VERSION = "#{STRING} (r#{REV})"
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -22,9 +22,9 @@ and type:
|
|
22
22
|
|
23
23
|
ruby find_rspecs_home_page.rb --format specdoc
|
24
24
|
|
25
|
-
Or better:
|
25
|
+
Or better - if you want to generate a super-hot HTML report with screenshots:
|
26
26
|
|
27
|
-
|
27
|
+
spec find_rspecs_home_page.rb --require ../web_test_html_formatter.rb --format WebTestHtmlFormatter > report/report.html
|
28
28
|
|
29
29
|
And upload find_rspecs_home_page.html to your project's web page or intranet.
|
30
30
|
This will give immediate visibility to the intended behaviour of your web app,
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/rspec_watir'
|
2
|
+
|
3
|
+
context "Google's search page" do
|
4
|
+
|
5
|
+
setup do
|
6
|
+
@browser.goto('http://www.google.com')
|
7
|
+
end
|
8
|
+
|
9
|
+
specify "should find rspec's home page when I search for rspec" do
|
10
|
+
@browser.text_field(:name, "q").set("rspec")
|
11
|
+
@browser.button(:name, "btnG").click
|
12
|
+
@browser.contains_text("rspec.rubyforge.org").should_not_be nil # should_contain_text is RSpec sugar
|
13
|
+
end
|
14
|
+
|
15
|
+
specify "should find rspec's home page when I search for 'better than fudge' (will probably fail)" do
|
16
|
+
@browser.text_field(:name, "q").set("better than fudge")
|
17
|
+
@browser.button(:name, "btnG").click
|
18
|
+
@browser.contains_text("rspec.rubyforge.org").should_not_be nil
|
19
|
+
end
|
20
|
+
|
21
|
+
specify "should not find Ali G when I search for respec" do
|
22
|
+
@browser.text_field(:name, "q").set("respec")
|
23
|
+
@browser.button(:name, "btnG").click
|
24
|
+
@browser.contains_text("Ali G").should_be nil
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
File without changes
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'spec'
|
3
|
-
require '
|
3
|
+
require 'fileutils'
|
4
|
+
require File.dirname(__FILE__) + '/../web_test_html_formatter_helper'
|
4
5
|
|
5
6
|
# Comment out to enable ActiveRecord fixtures
|
6
7
|
#require 'active_record'
|
@@ -11,13 +12,22 @@ require 'watir'
|
|
11
12
|
#ActiveRecord::Base.establish_connection(config['db'])
|
12
13
|
|
13
14
|
class RSpecWatir
|
15
|
+
include WebTestHtmlFormatterHelper
|
16
|
+
|
17
|
+
@@img_dir = File.dirname(__FILE__) + '/report/images'
|
18
|
+
FileUtils.mkdir_p(@@img_dir) unless File.exist?(@@img_dir)
|
19
|
+
@@n = 1
|
20
|
+
|
14
21
|
def setup
|
15
22
|
#Fixtures.create_fixtures($fixture_path, @@fixtures)
|
16
|
-
@browser = Watir::
|
23
|
+
@browser = Watir::Browser.new
|
17
24
|
end
|
18
25
|
|
19
26
|
def teardown
|
20
|
-
|
27
|
+
save_screenshots(@@img_dir, @@n)
|
28
|
+
save_source(@@img_dir, @@n, @browser.html)
|
29
|
+
@@n += 1
|
30
|
+
@browser.close unless RUBY_PLATFORM =~ /darwin/
|
21
31
|
end
|
22
32
|
|
23
33
|
#def self.fixtures(*testdata)
|
@@ -34,12 +44,3 @@ module Spec
|
|
34
44
|
end
|
35
45
|
end
|
36
46
|
end
|
37
|
-
|
38
|
-
# Extensions to Watir to make it play nicer with RSpec
|
39
|
-
module Watir
|
40
|
-
class IE
|
41
|
-
# @browser.should_contain("bla bla")
|
42
|
-
# @browser.should_not_contain("bla bla")
|
43
|
-
alias_method :contain?, :contains_text
|
44
|
-
end
|
45
|
-
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# Customizes the HTML report to include screenshots and browser source, which
|
2
|
+
# are saved in teardown defined in rspec_watir.rb
|
3
|
+
class WebTestHtmlFormatter < Spec::Runner::Formatter::HtmlFormatter
|
4
|
+
def extra_failure_content
|
5
|
+
@output.puts " <div><a href=\"images/#{@current_count}.png\"><img src=\"images/#{@current_count}_thumb.png\"></a></div>"
|
6
|
+
@output.puts " <div><a href=\"images/#{@current_count}.html\">HTML source</a></div>"
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'RMagick'
|
3
|
+
|
4
|
+
# include this module in your spec and call +save_screenshot+ and +save_source+ from
|
5
|
+
# teardown.
|
6
|
+
module WebTestHtmlFormatterHelper
|
7
|
+
if RUBY_PLATFORM =~ /darwin/
|
8
|
+
require File.dirname(__FILE__) + '/web_test_html_formatter_osx_helper'
|
9
|
+
include WebTestHtmlFormatterOsxHelper
|
10
|
+
Watir::Browser = Watir::Safari
|
11
|
+
else
|
12
|
+
require File.dirname(__FILE__) + '/web_test_html_formatter_win_helper'
|
13
|
+
include WebTestHtmlFormatterWinHelper
|
14
|
+
Watir::Browser = Watir::IE
|
15
|
+
end
|
16
|
+
|
17
|
+
def save_thumb(img, dir, spec_number)
|
18
|
+
thumb = img.scale(0.25)
|
19
|
+
thumb_file = "#{dir}/#{spec_number}_thumb.png"
|
20
|
+
thumb.write(thumb_file)
|
21
|
+
end
|
22
|
+
|
23
|
+
def save_source(dir, spec_number, html)
|
24
|
+
File.open("#{dir}/#{spec_number}.html", "w") {|io| io.write(html)}
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'safariwatir'
|
3
|
+
|
4
|
+
module WebTestHtmlFormatterOsxHelper
|
5
|
+
def save_screenshots(dir, spec_number)
|
6
|
+
img_path = "#{dir}/#{spec_number}.png"
|
7
|
+
# How do we capture the current window??
|
8
|
+
`screencapture #{img_path}`
|
9
|
+
|
10
|
+
img = Magick::Image.read(img_path)[0]
|
11
|
+
save_thumb(img, dir, spec_number)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class Watir::AppleScripter
|
16
|
+
def document_html
|
17
|
+
execute(%|document.documentElement.innerHTML;|)
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'win32screenshot'
|
3
|
+
require 'watir'
|
4
|
+
|
5
|
+
module WebTestHtmlFormatterWinHelper
|
6
|
+
def save_screenshots(dir, spec_number)
|
7
|
+
width, height, bmp = Win32::Screenshot.foreground
|
8
|
+
|
9
|
+
img = Magick::Image.from_blob(bmp)[0]
|
10
|
+
img_path = "#{dir}/#{spec_number}.png"
|
11
|
+
img.write(img_path)
|
12
|
+
save_thumb(img, dir, spec_number)
|
13
|
+
end
|
14
|
+
end
|
metadata
CHANGED
@@ -3,9 +3,9 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: rspec
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.7.
|
7
|
-
date: 2006-
|
8
|
-
summary: RSpec-0.7.
|
6
|
+
version: 0.7.4
|
7
|
+
date: 2006-12-02 00:00:00 +01:00
|
8
|
+
summary: RSpec-0.7.4 (r1201) - BDD for Ruby http://rspec.rubyforge.org/
|
9
9
|
require_paths:
|
10
10
|
- lib
|
11
11
|
email: rspec-devel@rubyforge.org
|
@@ -39,20 +39,22 @@ files:
|
|
39
39
|
- Rakefile
|
40
40
|
- README
|
41
41
|
- lib/spec.rb
|
42
|
+
- lib/spec/callback.rb
|
42
43
|
- lib/spec/expectations.rb
|
43
44
|
- lib/spec/mocks.rb
|
44
45
|
- lib/spec/runner.rb
|
45
46
|
- lib/spec/version.rb
|
47
|
+
- lib/spec/callback/callback_container.rb
|
48
|
+
- lib/spec/callback/extensions/module.rb
|
49
|
+
- lib/spec/callback/extensions/object.rb
|
46
50
|
- lib/spec/expectations/diff.rb
|
47
51
|
- lib/spec/expectations/errors.rb
|
48
52
|
- lib/spec/expectations/extensions.rb
|
49
53
|
- lib/spec/expectations/should.rb
|
50
54
|
- lib/spec/expectations/sugar.rb
|
51
55
|
- lib/spec/expectations/differs/default.rb
|
52
|
-
- lib/spec/expectations/extensions/inspect_for_expectation_not_met_error.rb
|
53
56
|
- lib/spec/expectations/extensions/numeric.rb
|
54
57
|
- lib/spec/expectations/extensions/object.rb
|
55
|
-
- lib/spec/expectations/extensions/symbol.rb
|
56
58
|
- lib/spec/expectations/should/base.rb
|
57
59
|
- lib/spec/expectations/should/change.rb
|
58
60
|
- lib/spec/expectations/should/have.rb
|
@@ -84,7 +86,6 @@ files:
|
|
84
86
|
- lib/spec/runner/spec_should_raise_handler.rb
|
85
87
|
- lib/spec/runner/specification.rb
|
86
88
|
- lib/spec/runner/extensions/kernel.rb
|
87
|
-
- lib/spec/runner/extensions/object.rb
|
88
89
|
- lib/spec/runner/formatter/base_text_formatter.rb
|
89
90
|
- lib/spec/runner/formatter/html_formatter.rb
|
90
91
|
- lib/spec/runner/formatter/progress_bar_formatter.rb
|
@@ -103,14 +104,18 @@ files:
|
|
103
104
|
- examples/stack_spec.rb
|
104
105
|
- examples/stubbing_example.rb
|
105
106
|
- examples/test_case_spec.rb
|
106
|
-
- vendor/
|
107
|
-
- vendor/
|
108
|
-
- vendor/
|
109
|
-
- vendor/
|
110
|
-
- vendor/selenium/find_rspecs_home_page.rb
|
111
|
-
- vendor/selenium/rspec_selenium.rb
|
112
|
-
- vendor/
|
113
|
-
- vendor/
|
107
|
+
- vendor/web_spec/web_test_html_formatter.rb
|
108
|
+
- vendor/web_spec/web_test_html_formatter_helper.rb
|
109
|
+
- vendor/web_spec/web_test_html_formatter_osx_helper.rb
|
110
|
+
- vendor/web_spec/web_test_html_formatter_win_helper.rb
|
111
|
+
- vendor/web_spec/selenium/find_rspecs_home_page.rb
|
112
|
+
- vendor/web_spec/selenium/rspec_selenium.rb
|
113
|
+
- vendor/web_spec/watir/find_rspecs_home_page.rb
|
114
|
+
- vendor/web_spec/watir/rspec_watir.rb
|
115
|
+
- vendor/web_spec/selenium/README.txt
|
116
|
+
- vendor/web_spec/watir/find_rspecs_home_page.txt
|
117
|
+
- vendor/web_spec/watir/README.txt
|
118
|
+
- vendor/web_spec/selenium/start_browser_once.patch
|
114
119
|
test_files: []
|
115
120
|
|
116
121
|
rdoc_options:
|
@@ -1,15 +0,0 @@
|
|
1
|
-
class Object
|
2
|
-
def inspect_for_expectation_not_met_error
|
3
|
-
return "#{inspect}" if inspect.include? "<"
|
4
|
-
return "<#{inspect}>" unless inspect.include? "<"
|
5
|
-
end
|
6
|
-
end
|
7
|
-
class TrueClass; def inspect_for_expectation_not_met_error; "true" end end
|
8
|
-
class FalseClass; def inspect_for_expectation_not_met_error; "false" end end
|
9
|
-
class NilClass; def inspect_for_expectation_not_met_error; "nil" end end
|
10
|
-
class Class; def inspect_for_expectation_not_met_error; "<#{name}>" end end
|
11
|
-
class Proc; def inspect_for_expectation_not_met_error; "<Proc>" end end
|
12
|
-
class Array; def inspect_for_expectation_not_met_error; inspect end end
|
13
|
-
class String; def inspect_for_expectation_not_met_error; inspect end end
|
14
|
-
class Numeric; def inspect_for_expectation_not_met_error; inspect end end
|
15
|
-
class Hash; def inspect_for_expectation_not_met_error; inspect end end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# http://eigenclass.org/hiki.rb?bounded+space+instance_exec
|
2
|
-
class Object
|
3
|
-
module InstanceExecHelper; end
|
4
|
-
include InstanceExecHelper
|
5
|
-
def instance_exec(*args, &block)
|
6
|
-
begin
|
7
|
-
old_critical, Thread.critical = Thread.critical, true
|
8
|
-
n = 0
|
9
|
-
n += 1 while respond_to?(mname="__instance_exec#{n}")
|
10
|
-
InstanceExecHelper.module_eval{ define_method(mname, &block) }
|
11
|
-
ensure
|
12
|
-
Thread.critical = old_critical
|
13
|
-
end
|
14
|
-
begin
|
15
|
-
ret = send(mname, *args)
|
16
|
-
ensure
|
17
|
-
InstanceExecHelper.module_eval{ remove_method(mname) } rescue nil
|
18
|
-
end
|
19
|
-
ret
|
20
|
-
end
|
21
|
-
end
|