Permalink
Browse files

Updated MSpec source to ef112bbe.

  • Loading branch information...
Brian Ford
Brian Ford committed Apr 29, 2009
1 parent 025b132 commit 63f7c37ad2624fbfbb712c3d9dd4f89f16112230
@@ -0,0 +1,153 @@
+From b29d3477bfaae5d4de3fd4c10eb64203773d3bdd Mon Sep 17 00:00:00 2001
+From: Brian Ford <bford@engineyard.com>
+Date: Wed, 29 Apr 2009 12:22:12 -0700
+Subject: [PATCH 1/3] Added -d, --debug to set MSpec debugging (verbosity) flag.
+
+---
+ lib/mspec/commands/mspec-ci.rb | 1 +
+ lib/mspec/commands/mspec-run.rb | 1 +
+ lib/mspec/commands/mspec-tag.rb | 1 +
+ lib/mspec/utils/options.rb | 7 +++++++
+ spec/commands/mspec_ci_spec.rb | 5 +++++
+ spec/commands/mspec_run_spec.rb | 5 +++++
+ spec/commands/mspec_tag_spec.rb | 5 +++++
+ spec/utils/options_spec.rb | 26 ++++++++++++++++++++++++++
+ 8 files changed, 51 insertions(+), 0 deletions(-)
+
+diff --git a/lib/mspec/commands/mspec-ci.rb b/lib/mspec/commands/mspec-ci.rb
+index e838ffc..f5bc84f 100644
+--- a/lib/mspec/commands/mspec-ci.rb
++++ b/lib/mspec/commands/mspec-ci.rb
+@@ -42,6 +42,7 @@ class MSpecCI < MSpecScript
+ options.action_filters
+
+ options.doc "\n Help!"
++ options.debug
+ options.version MSpec::VERSION
+ options.help
+
+diff --git a/lib/mspec/commands/mspec-run.rb b/lib/mspec/commands/mspec-run.rb
+index 547a484..1026f71 100644
+--- a/lib/mspec/commands/mspec-run.rb
++++ b/lib/mspec/commands/mspec-run.rb
+@@ -53,6 +53,7 @@ class MSpecRun < MSpecScript
+ options.action_filters
+
+ options.doc "\n Help!"
++ options.debug
+ options.version MSpec::VERSION
+ options.help
+
+diff --git a/lib/mspec/commands/mspec-tag.rb b/lib/mspec/commands/mspec-tag.rb
+index 804599a..bba35e7 100644
+--- a/lib/mspec/commands/mspec-tag.rb
++++ b/lib/mspec/commands/mspec-tag.rb
+@@ -72,6 +72,7 @@ class MSpecTag < MSpecScript
+ end
+
+ options.doc "\n Help!"
++ options.debug
+ options.version MSpec::VERSION
+ options.help
+
+diff --git a/lib/mspec/utils/options.rb b/lib/mspec/utils/options.rb
+index 0a7d815..52183f6 100644
+--- a/lib/mspec/utils/options.rb
++++ b/lib/mspec/utils/options.rb
+@@ -440,4 +440,11 @@ class MSpecOptions
+ config[:gdb] = true
+ end
+ end
++
++ def debug
++ on("-d", "--debug",
++ "Set MSpec debugging flag for more verbose output") do
++ $MSPEC_DEBUG = true
++ end
++ end
+ end
+diff --git a/spec/commands/mspec_ci_spec.rb b/spec/commands/mspec_ci_spec.rb
+index c6c84f7..b0f1515 100644
+--- a/spec/commands/mspec_ci_spec.rb
++++ b/spec/commands/mspec_ci_spec.rb
+@@ -88,6 +88,11 @@ describe MSpecCI, "#options" do
+ @script.options
+ end
+
++ it "enables the debug option" do
++ @options.should_receive(:debug)
++ @script.options @argv
++ end
++
+ it "calls #custom_options" do
+ @script.should_receive(:custom_options).with(@options)
+ @script.options
+diff --git a/spec/commands/mspec_run_spec.rb b/spec/commands/mspec_run_spec.rb
+index a53aa86..6d930d6 100644
+--- a/spec/commands/mspec_run_spec.rb
++++ b/spec/commands/mspec_run_spec.rb
+@@ -118,6 +118,11 @@ describe MSpecRun, "#options" do
+ @script.options @argv
+ end
+
++ it "enables the debug option" do
++ @options.should_receive(:debug)
++ @script.options @argv
++ end
++
+ it "exits if there are no files to process" do
+ @options.should_receive(:parse).and_return([])
+ @script.should_receive(:exit)
+diff --git a/spec/commands/mspec_tag_spec.rb b/spec/commands/mspec_tag_spec.rb
+index 2c048b3..d2092af 100644
+--- a/spec/commands/mspec_tag_spec.rb
++++ b/spec/commands/mspec_tag_spec.rb
+@@ -98,6 +98,11 @@ describe MSpecTag, "#options" do
+ @script.options @argv
+ end
+
++ it "enables the debug option" do
++ @options.should_receive(:debug)
++ @script.options @argv
++ end
++
+ it "calls #custom_options" do
+ @script.should_receive(:custom_options).with(@options)
+ @script.options @argv
+diff --git a/spec/utils/options_spec.rb b/spec/utils/options_spec.rb
+index e488b89..c8383f6 100644
+--- a/spec/utils/options_spec.rb
++++ b/spec/utils/options_spec.rb
+@@ -1290,3 +1290,29 @@ describe "The --spec-gdb option" do
+ @config[:gdb].should == true
+ end
+ end
++
++describe "The -d, --debug option" do
++ before :each do
++ @options, @config = new_option
++ @options.debug
++ end
++
++ after :each do
++ $MSPEC_DEBUG = nil
++ end
++
++ it "is enabled with #debug" do
++ @options.stub!(:on)
++ @options.should_receive(:on).with("-d", "--debug", an_instance_of(String))
++ @options.debug
++ end
++
++ it "sets $MSPEC_DEBUG to true" do
++ ["-d", "--debug"].each do |opt|
++ $MSPEC_DEBUG.should_not be_true
++ @options.parse opt
++ $MSPEC_DEBUG.should be_true
++ $MSPEC_DEBUG = nil
++ end
++ end
++end
+--
+1.6.1.1
+
@@ -0,0 +1,124 @@
+From 4a1dcb3175a35b5c30ab0613632d25ad84d6ad11 Mon Sep 17 00:00:00 2001
+From: Brian Ford <bford@engineyard.com>
+Date: Wed, 29 Apr 2009 14:10:20 -0700
+Subject: [PATCH 2/3] Fixed backtrace filtering.
+
+Set the config option :backtrace_filter to a regexp of the
+paths to filter out of the backtrace. Pass -d to mspec-run,
+mspec-tag, or mspec-ci to NOT filter backtraces.
+---
+ lib/mspec/runner.rb | 1 +
+ lib/mspec/runner/exception.rb | 7 ++++---
+ spec/expectations/should.rb | 1 +
+ spec/runner/exception_spec.rb | 27 +++++++++++++++++----------
+ 4 files changed, 23 insertions(+), 13 deletions(-)
+
+diff --git a/lib/mspec/runner.rb b/lib/mspec/runner.rb
+index 1485626..541ec38 100644
+--- a/lib/mspec/runner.rb
++++ b/lib/mspec/runner.rb
+@@ -2,6 +2,7 @@ require 'mspec/mocks'
+ require 'mspec/runner/mspec'
+ require 'mspec/runner/context'
+ require 'mspec/runner/example'
++require 'mspec/runner/exception'
+ require 'mspec/runner/object'
+ require 'mspec/runner/formatters'
+ require 'mspec/runner/actions'
+diff --git a/lib/mspec/runner/exception.rb b/lib/mspec/runner/exception.rb
+index acc07de..a673624 100644
+--- a/lib/mspec/runner/exception.rb
++++ b/lib/mspec/runner/exception.rb
+@@ -1,8 +1,6 @@
+ class ExceptionState
+ attr_reader :description, :describe, :it, :exception
+
+- PATH = /#{File.expand_path(File.dirname(__FILE__) + '/../../..')}/
+-
+ def initialize(state, location, exception)
+ @exception = exception
+
+@@ -33,11 +31,14 @@ class ExceptionState
+ end
+
+ def backtrace
++ @backtrace_filter ||= MSpecScript.config[:backtrace_filter]
++
+ begin
+ bt = @exception.awesome_backtrace.show.split "\n"
+ rescue Exception
+ bt = @exception.backtrace || []
+ end
+- bt.reject { |line| PATH =~ line }.join("\n")
++
++ bt.select { |line| $MSPEC_DEBUG or @backtrace_filter !~ line }.join("\n")
+ end
+ end
+diff --git a/spec/expectations/should.rb b/spec/expectations/should.rb
+index 4abe02a..8404ff0 100644
+--- a/spec/expectations/should.rb
++++ b/spec/expectations/should.rb
+@@ -1,5 +1,6 @@
+ $: << File.dirname(__FILE__) + '/../../lib'
+ require 'mspec'
++require 'mspec/utils/script'
+
+ # The purpose of these specs is to confirm that the #should
+ # and #should_not methods are functioning appropriately. We
+diff --git a/spec/runner/exception_spec.rb b/spec/runner/exception_spec.rb
+index 0e3aa2a..f44dd89 100644
+--- a/spec/runner/exception_spec.rb
++++ b/spec/runner/exception_spec.rb
+@@ -2,6 +2,7 @@ require File.dirname(__FILE__) + '/../spec_helper'
+ require 'mspec/expectations/expectations'
+ require 'mspec/runner/example'
+ require 'mspec/runner/exception'
++require 'mspec/utils/script'
+
+ describe ExceptionState, "#initialize" do
+ it "takes a state, location (e.g. before :each), and exception" do
+@@ -110,25 +111,31 @@ end
+
+ describe ExceptionState, "#backtrace" do
+ before :each do
+- @action = mock("action")
+- def @action.exception(exc)
+- ScratchPad.record exc.exception
++ begin
++ raise Exception
++ rescue Exception => @exception
++ @exc = ExceptionState.new @state, "", @exception
+ end
+- MSpec.register :exception, @action
+-
+- ScratchPad.clear
+- MSpec.protect("") { raise Exception }
++ end
+
+- @exc = ExceptionState.new @state, "", ScratchPad.recorded
++ after :each do
++ $MSPEC_DEBUG = nil
+ end
+
+ it "returns a string representation of the exception backtrace" do
+ @exc.backtrace.should be_kind_of(String)
+ end
+
+- it "strips MSpec files from the backtrace" do
++ it "does not filter files from the backtrace if $MSPEC_DEBUG is true" do
++ $MSPEC_DEBUG = true
++ @exc.backtrace.should == @exception.backtrace.join("\n")
++ end
++
++ it "filters files matching config[:backtrace_filter]" do
++ MSpecScript.set :backtrace_filter, %r[mspec/lib]
++ $MSPEC_DEBUG = nil
+ @exc.backtrace.split("\n").each do |line|
+- line.should_not =~ ExceptionState::PATH
++ line.should_not =~ %r[mspec/lib]
+ end
+ end
+ end
+--
+1.6.1.1
+
@@ -42,6 +42,7 @@ def options(argv=ARGV)
options.action_filters
options.doc "\n Help!"
+ options.debug
options.version MSpec::VERSION
options.help
@@ -53,6 +53,7 @@ def options(argv=ARGV)
options.action_filters
options.doc "\n Help!"
+ options.debug
options.version MSpec::VERSION
options.help
@@ -72,6 +72,7 @@ def options(argv=ARGV)
end
options.doc "\n Help!"
+ options.debug
options.version MSpec::VERSION
options.help
@@ -12,9 +12,12 @@
require 'mspec/matchers/equal_element'
require 'mspec/matchers/equal_utf16'
require 'mspec/matchers/have_constant'
+require 'mspec/matchers/have_class_variable'
require 'mspec/matchers/have_instance_method'
+require 'mspec/matchers/have_instance_variable'
require 'mspec/matchers/have_method'
require 'mspec/matchers/have_private_instance_method'
+require 'mspec/matchers/have_public_instance_method'
require 'mspec/matchers/include'
require 'mspec/matchers/match_yaml'
require 'mspec/matchers/raise_error'
@@ -0,0 +1,12 @@
+require 'mspec/matchers/variable'
+
+class HaveClassVariableMatcher < VariableMatcher
+ self.variables_method = :class_variables
+ self.description = 'class variable'
+end
+
+class Object
+ def have_class_variable(variable)
+ HaveClassVariableMatcher.new(variable)
+ end
+end
@@ -1,30 +1,12 @@
-require 'mspec/matchers/stringsymboladapter'
+require 'mspec/matchers/variable'
-class HaveConstantMatcher
- include StringSymbolAdapter
-
- def initialize(name)
- @name = convert_name name
- end
-
- def matches?(mod)
- @mod = mod
- @mod.constants.include? @name
- end
-
- def failure_message
- ["Expected #{@mod} to have constant '#{@name.to_s}'",
- "but it does not"]
- end
-
- def negative_failure_message
- ["Expected #{@mod} NOT to have constant '#{@name.to_s}'",
- "but it does"]
- end
+class HaveConstantMatcher < VariableMatcher
+ self.variables_method = :constants
+ self.description = 'constant'
end
class Object
- def have_constant(name)
- HaveConstantMatcher.new name
+ def have_constant(variable)
+ HaveConstantMatcher.new(variable)
end
end
@@ -0,0 +1,12 @@
+require 'mspec/matchers/variable'
+
+class HaveInstanceVariableMatcher < VariableMatcher
+ self.variables_method = :instance_variables
+ self.description = 'instance variable'
+end
+
+class Object
+ def have_instance_variable(variable)
+ HaveInstanceVariableMatcher.new(variable)
+ end
+end
Oops, something went wrong.

0 comments on commit 63f7c37

Please sign in to comment.