Permalink
Browse files

Switch to RSpec 2, RR, Bundler

I've been seeing suspicious segfaults during spec suite runs and had
noticed that they mostly occurred when calling the "paths" method on
a scanner instance.

As this particular call is mocked or stubbed, I wondered if it might be
fixed by changing to another mocking framework. That is what this commit
does.

The easiest way I know to do this and have full control over the
versions involved is to use Bundler, so I'm switching to that in this
commit too.

Note that it doesn't actually fix the segfaults. Further investigation
shows that it has nothing to do with mocking/stubbing; the common
trigger is literally _any_ use of rb_funcall in the extension at all.

I suspect some mismatch between the version of Ruby used in the spec
environment and the version used at runtime from inside Vim, because the
latter works perfectly.

So, even though this switch doesn't fix the problem it set out to, I am
going to keep it as it brings us a nicer mocking/stubbing syntax.

Signed-off-by: Wincent Colaiuta <win@wincent.com>
  • Loading branch information...
1 parent 90f3d9c commit 5b423c7c3e2dfa672a7152d95a936d1738d6f390 @wincent committed Jul 10, 2010
Showing with 50 additions and 19 deletions.
  1. +1 −0 .rspec
  2. +3 −0 Gemfile
  3. +21 −0 Gemfile.lock
  4. +6 −7 Rakefile
  5. +1 −1 spec/command-t/finder_spec.rb
  6. +5 −5 spec/command-t/matcher_spec.rb
  7. +2 −2 spec/command-t/scanner_spec.rb
  8. +0 −4 spec/spec.opts
  9. +11 −0 spec/spec_helper.rb
View
1 .rspec
@@ -0,0 +1 @@
+--colour
View
@@ -0,0 +1,3 @@
+gem 'rake'
+gem 'rr'
+gem 'rspec', '>= 2.0.0.beta.16'
View
@@ -0,0 +1,21 @@
+GEM
+ specs:
+ diff-lcs (1.1.2)
+ rake (0.8.7)
+ rr (0.10.11)
+ rspec (2.0.0.beta.16)
+ rspec-core (= 2.0.0.beta.16)
+ rspec-expectations (= 2.0.0.beta.16)
+ rspec-mocks (= 2.0.0.beta.16)
+ rspec-core (2.0.0.beta.16)
+ rspec-expectations (2.0.0.beta.16)
+ diff-lcs (>= 1.1.2)
+ rspec-mocks (2.0.0.beta.16)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ rake
+ rr
+ rspec (>= 2.0.0.beta.16)
View
@@ -1,7 +1,7 @@
-begin
- require 'spec/rake/spectask'
-rescue LoadError
-end
+require 'rubygems'
+require 'bundler'
+Bundler.setup
+require 'rspec/core/rake_task'
def bail_on_failure
exitstatus = $?.exitstatus
@@ -13,9 +13,8 @@ end
task :default => :spec
desc 'Run specs'
-Spec::Rake::SpecTask.new do |t|
- t.spec_files = FileList['spec/**/*_spec.rb']
- t.spec_opts = ['--options', 'spec/spec.opts']
+RSpec::Core::RakeTask.new do |t|
+ t.pattern = './spec/**/*_spec.rb'
end
desc 'Create vimball archive'
@@ -41,7 +41,7 @@
before do
# scanner will call VIM's expand() function for exclusion filtering
- VIM.stub!(:evaluate).with(/expand\(.+\)/).and_return('0')
+ stub(VIM).evaluate(/expand\(.+\)/) { '0' }
end
describe 'sorted_matches_for method' do
@@ -35,7 +35,7 @@
describe 'matches_for method' do
before do
- @scanner = mock(CommandT::Scanner)
+ @scanner = Object.new
end
it 'should raise an ArgumentError if passed nil' do
@@ -45,20 +45,20 @@
end
it 'should return empty array when source array empty' do
- @scanner.stub(:paths).and_return([])
+ stub(@scanner).paths { [] }
@no_paths = CommandT::Matcher.new @scanner
@no_paths.matches_for('foo').should == []
@no_paths.matches_for('').should == []
end
it 'should return empty array when no matches' do
- @scanner.stub(:paths).and_return(['foo/bar', 'foo/baz', 'bing'])
+ stub(@scanner).paths { ['foo/bar', 'foo/baz', 'bing'] }
@no_matches = CommandT::Matcher.new @scanner
@no_matches.matches_for('xyz').should == []
end
it 'should return matching paths' do
- @scanner.stub(:paths).and_return(['foo/bar', 'foo/baz', 'bing'])
+ stub(@scanner).paths { ['foo/bar', 'foo/baz', 'bing'] }
@foo_paths = CommandT::Matcher.new @scanner
matches = @foo_paths.matches_for('z')
matches.map { |m| m.to_s }.should == ['foo/baz']
@@ -67,7 +67,7 @@
end
it 'should perform case-insensitive matching' do
- @scanner.stub(:paths).and_return(['Foo'])
+ stub(@scanner).paths { ['Foo'] }
@path = CommandT::Matcher.new @scanner
matches = @path.matches_for('f')
matches.map { |m| m.to_s }.should == ['Foo']
@@ -30,7 +30,7 @@
@scanner = CommandT::Scanner.new @dir
# scanner will call VIM's expand() function for exclusion filtering
- VIM.stub!(:evaluate).with(/expand\(.+\)/).and_return('0')
+ stub(VIM).evaluate(/expand\(.+\)/) { '0' }
end
describe 'paths method' do
@@ -66,7 +66,7 @@
describe "'wildignore' exclusion" do
it "should call on VIM's expand() function for pattern filtering" do
@scanner = CommandT::Scanner.new @dir
- VIM.should_receive(:evaluate).with(/expand\(.+\)/).exactly(10).times
+ mock(VIM).evaluate(/expand\(.+\)/).times(10)
@scanner.paths
end
end
View
@@ -1,4 +0,0 @@
---color
---format progress
---loadby mtime
---reverse
View
@@ -21,7 +21,18 @@
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
+if !Object.const_defined?('Bundler')
+ require 'rubygems'
+ require 'bundler'
+ Bundler.setup
+end
+require 'rspec'
+
lib = File.expand_path('../ruby', File.dirname(__FILE__))
unless $LOAD_PATH.include? lib
$LOAD_PATH.unshift lib
end
+
+RSpec.configure do |config|
+ config.mock_framework = :rr
+end

0 comments on commit 5b423c7

Please sign in to comment.