summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Mair <jrmair@gmail.com>2017-09-26 13:31:53 +0200
committerGitHub <noreply@github.com>2017-09-26 13:31:53 +0200
commit72919e780c3cd48789aba009fdc11e0e52554ace (patch)
tree98237b180f7f8a8a64165fa7c51caa300c22d68c
parent0cc6cc8e15d08880585e8cb0c54e13c3cf937c54 (diff)
parenta4e02e622d381fa654f9f5e9710a673d58776128 (diff)
downloadmethod_source-72919e780c3cd48789aba009fdc11e0e52554ace.tar.gz
Merge pull request #45 from junaruga/feature/rspec
Replace Bacon to RSpec 3
-rw-r--r--.travis.yml7
-rw-r--r--Rakefile11
-rw-r--r--method_source.gemspec10
-rw-r--r--spec/method_source/code_helpers_spec.rb (renamed from test/test_code_helpers.rb)10
-rw-r--r--spec/method_source_spec.rb (renamed from test/test.rb)69
-rw-r--r--spec/spec_helper.rb (renamed from test/test_helper.rb)3
6 files changed, 61 insertions, 49 deletions
diff --git a/.travis.yml b/.travis.yml
index e0c78b8..5e548f9 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,3 +1,5 @@
+# To use rbx environment.
+dist: trusty
bundler_args: "--verbose"
before_install:
- gem update --system
@@ -5,10 +7,9 @@ before_install:
- gem update bundler
rvm:
- 1.8.7
- - 1.9.2
- 1.9.3
- ree
- - rbx
+ - rbx-3
- jruby
- jruby-head
- 2.0.0
@@ -21,7 +22,7 @@ matrix:
allow_failures:
- rvm: ruby-head
- rvm: jruby-head
- - rvm: rbx
+ - rvm: rbx-3
fast_finish: true
notifications:
irc: "irc.freenode.org#pry"
diff --git a/Rakefile b/Rakefile
index 7dad800..367d510 100644
--- a/Rakefile
+++ b/Rakefile
@@ -20,16 +20,17 @@ def apply_spec_defaults(s)
s.description = s.summary
s.require_path = 'lib'
- s.add_development_dependency("bacon","~>1.1.0")
+ s.add_development_dependency("rspec","~>3.6")
s.add_development_dependency("rake", "~>0.9")
s.homepage = "http://banisterfiend.wordpress.com"
s.has_rdoc = 'yard'
s.files = `git ls-files`.split("\n")
- s.test_files = `git ls-files -- test/*`.split("\n")
+ s.test_files = `git ls-files -- spec/*`.split("\n")
end
-task :test do
- sh "bacon -q #{direc}/test/test.rb #{direc}/test/test_code_helpers.rb"
+require "rspec/core/rake_task"
+RSpec::Core::RakeTask.new(:spec) do |t|
+ t.ruby_opts = %w[-w]
end
desc "reinstall gem"
@@ -39,7 +40,7 @@ task :reinstall => :gems do
end
desc "Set up and run tests"
-task :default => [:test]
+task :default => [:spec]
desc "Build the gemspec file"
task :gemspec => "ruby:gemspec"
diff --git a/method_source.gemspec b/method_source.gemspec
index d24b3d9..2b2bc40 100644
--- a/method_source.gemspec
+++ b/method_source.gemspec
@@ -9,25 +9,25 @@ Gem::Specification.new do |s|
s.date = "2012-10-17"
s.description = "retrieve the sourcecode for a method"
s.email = "jrmair@gmail.com"
- s.files = [".gemtest", ".travis.yml", ".yardopts", "Gemfile", "LICENSE", "README.markdown", "Rakefile", "lib/method_source.rb", "lib/method_source/code_helpers.rb", "lib/method_source/source_location.rb", "lib/method_source/version.rb", "method_source.gemspec", "test/test.rb", "test/test_code_helpers.rb", "test/test_helper.rb"]
+ s.files = [".gemtest", ".travis.yml", ".yardopts", "Gemfile", "LICENSE", "README.markdown", "Rakefile", "lib/method_source.rb", "lib/method_source/code_helpers.rb", "lib/method_source/source_location.rb", "lib/method_source/version.rb", "method_source.gemspec", "spec/method_source/code_helpers_spec.rb", "spec/method_source_spec.rb", "spec/spec_helper.rb"]
s.homepage = "http://banisterfiend.wordpress.com"
s.require_paths = ["lib"]
s.rubygems_version = "1.8.23"
s.summary = "retrieve the sourcecode for a method"
- s.test_files = ["test/test.rb", "test/test_code_helpers.rb", "test/test_helper.rb"]
+ s.test_files = ["spec/method_source/code_helpers_spec.rb", "spec/method_source_spec.rb", "spec/spec_helper.rb"]
if s.respond_to? :specification_version then
s.specification_version = 3
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
- s.add_development_dependency(%q<bacon>, ["~> 1.1.0"])
+ s.add_development_dependency(%q<rspec>, ["~> 3.6"])
s.add_development_dependency(%q<rake>, ["~> 0.9"])
else
- s.add_dependency(%q<bacon>, ["~> 1.1.0"])
+ s.add_dependency(%q<rspec>, ["~> 3.6"])
s.add_dependency(%q<rake>, ["~> 0.9"])
end
else
- s.add_dependency(%q<bacon>, ["~> 1.1.0"])
+ s.add_dependency(%q<rspec>, ["~> 3.6"])
s.add_dependency(%q<rake>, ["~> 0.9"])
end
end
diff --git a/test/test_code_helpers.rb b/spec/method_source/code_helpers_spec.rb
index ba83a63..287ff89 100644
--- a/test/test_code_helpers.rb
+++ b/spec/method_source/code_helpers_spec.rb
@@ -1,3 +1,5 @@
+require 'spec_helper'
+
describe MethodSource::CodeHelpers do
before do
@tester = Object.new.extend(MethodSource::CodeHelpers)
@@ -17,9 +19,9 @@ describe MethodSource::CodeHelpers do
].each do |lines|
it "should not raise an error on broken lines: #{lines.join("\\n")}" do
1.upto(lines.size - 1) do |i|
- @tester.complete_expression?(lines[0...i].join("\n") + "\n").should == false
+ expect(@tester.complete_expression?(lines[0...i].join("\n") + "\n")).to be_falsy
end
- @tester.complete_expression?(lines.join("\n")).should == true
+ expect(@tester.complete_expression?(lines.join("\n"))).to be_truthy
end
end
@@ -33,9 +35,9 @@ describe MethodSource::CodeHelpers do
["o = Object.new.tap{ def o.render;","'MEH'", "}"] # in this case the syntax error is "expecting keyword_end".
]).compact.each do |foo|
it "should raise an error on invalid syntax like #{foo.inspect}" do
- lambda{
+ expect {
@tester.complete_expression?(foo.join("\n"))
- }.should.raise(SyntaxError)
+ }.to raise_error(SyntaxError)
end
end
end
diff --git a/test/test.rb b/spec/method_source_spec.rb
index b99f717..088c21f 100644
--- a/test/test.rb
+++ b/spec/method_source_spec.rb
@@ -1,26 +1,25 @@
-direc = File.expand_path(File.dirname(__FILE__))
-
-require 'rubygems'
-require 'bacon'
-require "#{direc}/../lib/method_source"
-require "#{direc}/test_helper"
+require 'spec_helper'
describe MethodSource do
describe "source_location (testing 1.8 implementation)" do
it 'should return correct source_location for a method' do
- method(:hello).source_location.first.should =~ /test_helper/
+ expect(method(:hello).source_location.first).to match(/spec_helper/)
end
it 'should not raise for immediate instance methods' do
[Symbol, Integer, TrueClass, FalseClass, NilClass].each do |immediate_class|
- lambda { immediate_class.instance_method(:to_s).source_location }.should.not.raise
+ expect do
+ immediate_class.instance_method(:to_s).source_location
+ end.not_to raise_error
end
end
it 'should not raise for immediate methods' do
[:a, 1, true, false, nil].each do |immediate|
- lambda { immediate.method(:to_s).source_location }.should.not.raise
+ expect do
+ immediate.method(:to_s).source_location
+ end.not_to raise_error
end
end
end
@@ -40,49 +39,55 @@ describe MethodSource do
end
it 'should define methods on Method and UnboundMethod and Proc' do
- Method.method_defined?(:source).should == true
- UnboundMethod.method_defined?(:source).should == true
- Proc.method_defined?(:source).should == true
+ expect(Method.method_defined?(:source)).to be_truthy
+ expect(UnboundMethod.method_defined?(:source)).to be_truthy
+ expect(Proc.method_defined?(:source)).to be_truthy
end
describe "Methods" do
it 'should return source for method' do
- method(:hello).source.should == @hello_source
+ expect(method(:hello).source).to eq(@hello_source)
end
it 'should return source for a method defined in a module' do
- M.instance_method(:hello).source.should == @hello_module_source
+ expect(M.instance_method(:hello).source).to eq(@hello_module_source)
end
it 'should return source for a singleton method as an instance method' do
- class << $o; self; end.instance_method(:hello).source.should == @hello_singleton_source
+ expect(class << $o
+ self
+ end.instance_method(:hello).source).to eq(@hello_singleton_source)
end
it 'should return source for a singleton method' do
- $o.method(:hello).source.should == @hello_singleton_source
+ expect($o.method(:hello).source).to eq(@hello_singleton_source)
end
it 'should return a comment for method' do
- method(:hello).comment.should == @hello_comment
+ expect(method(:hello).comment).to eq(@hello_comment)
end
# These tests fail because of http://jira.codehaus.org/browse/JRUBY-4576
unless defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
it 'should return source for an *_evaled method' do
- M.method(:hello_name).source.should == @hello_instance_evaled_source
- M.method(:name_two).source.should == @hello_instance_evaled_source_2
- M.instance_method(:hello_name).source.should == @hello_class_evaled_source
- M.instance_method(:hi_name).source.should == @hi_module_evaled_source
+ expect(M.method(:hello_name).source).to eq(@hello_instance_evaled_source)
+ expect(M.method(:name_two).source).to eq(@hello_instance_evaled_source_2)
+ expect(M.instance_method(:hello_name).source).to eq(@hello_class_evaled_source)
+ expect(M.instance_method(:hi_name).source).to eq(@hi_module_evaled_source)
end
end
it "should raise error for evaled methods that do not pass __FILE__ and __LINE__ + 1 as its arguments" do
- lambda { M.instance_method(:name_three).source }.should.raise MethodSource::SourceNotFoundError
+ expect do
+ M.instance_method(:name_three).source
+ end.to raise_error(MethodSource::SourceNotFoundError)
end
if !is_rbx?
it 'should raise for C methods' do
- lambda { method(:puts).source }.should.raise MethodSource::SourceNotFoundError
+ expect do
+ method(:puts).source
+ end.to raise_error(MethodSource::SourceNotFoundError)
end
end
end
@@ -90,19 +95,19 @@ describe MethodSource do
# if RUBY_VERSION =~ /1.9/ || is_rbx?
describe "Lambdas and Procs" do
it 'should return source for proc' do
- MyProc.source.should == @proc_source
+ expect(MyProc.source).to eq(@proc_source)
end
it 'should return an empty string if there is no comment' do
- MyProc.comment.should == ''
+ expect(MyProc.comment).to eq('')
end
it 'should return source for lambda' do
- MyLambda.source.should == @lambda_source
+ expect(MyLambda.source).to eq(@lambda_source)
end
it 'should return comment for lambda' do
- MyLambda.comment.should == @lambda_comment
+ expect(MyLambda.comment).to eq(@lambda_comment)
end
end
# end
@@ -116,23 +121,23 @@ describe MethodSource do
end
it "should correctly extract multi-line comments" do
- method(:comment_test1).comment.should == @comment1
+ expect(method(:comment_test1).comment).to eq(@comment1)
end
it "should correctly strip leading whitespace before comments" do
- method(:comment_test2).comment.should == @comment2
+ expect(method(:comment_test2).comment).to eq(@comment2)
end
it "should keep empty comment lines" do
- method(:comment_test3).comment.should == @comment3
+ expect(method(:comment_test3).comment).to eq(@comment3)
end
it "should ignore blank lines between comments" do
- method(:comment_test4).comment.should == @comment4
+ expect(method(:comment_test4).comment).to eq(@comment4)
end
it "should align all comments to same indent level" do
- method(:comment_test5).comment.should == @comment5
+ expect(method(:comment_test5).comment).to eq(@comment5)
end
end
end
diff --git a/test/test_helper.rb b/spec/spec_helper.rb
index 3aabdf1..0e5de61 100644
--- a/test/test_helper.rb
+++ b/spec/spec_helper.rb
@@ -1,3 +1,6 @@
+require 'method_source'
+require 'rspec'
+
def is_rbx?
defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /rbx/
end