summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorStas SUȘCOV <stas@nerd.ro>2021-11-02 22:50:54 +0000
committerStas SUȘCOV <stas@nerd.ro>2021-11-03 00:36:59 +0000
commit8e5a1520c80661c6997638b45e5050ff946d844d (patch)
treef2431f64adbbc21a369dc89c953a6f4d89b59aac /spec
parent836d7047ab5e7a1b2e7779e9a4b4fc2ba7f6cb1c (diff)
downloadmethod_source-8e5a1520c80661c6997638b45e5050ff946d844d.tar.gz
Allow fetching class/module comments.
Diffstat (limited to 'spec')
-rw-r--r--spec/method_source_spec.rb14
-rw-r--r--spec/spec_helper.rb6
2 files changed, 20 insertions, 0 deletions
diff --git a/spec/method_source_spec.rb b/spec/method_source_spec.rb
index c4e0669..1927670 100644
--- a/spec/method_source_spec.rb
+++ b/spec/method_source_spec.rb
@@ -30,6 +30,8 @@ describe MethodSource do
@hello_source = "def hello; :hello; end\n"
@hello_comment = "# A comment for hello\n# It spans two lines and is indented by 2 spaces\n"
@lambda_comment = "# This is a comment for MyLambda\n"
+ @module_comment = "# This is a comment for module\n"
+ @class_comment = "# This is a comment for class\n"
@lambda_source = "MyLambda = lambda { :lambda }\n"
@proc_source = "MyProc = Proc.new { :proc }\n"
@hello_instance_evaled_source = " def hello_\#{name}(*args)\n send_mesg(:\#{name}, *args)\n end\n"
@@ -109,6 +111,18 @@ describe MethodSource do
it 'should return comment for lambda' do
expect(MyLambda.comment).to eq(@lambda_comment)
end
+
+ it 'should return comment for module' do
+ expect(M.instance_method(:hello).module_comment).to eq(@module_comment)
+ end
+
+ it 'should return comment for class' do
+ expect(C.method(:hello).class_comment).to eq(@class_comment)
+ end
+
+ it 'should return comment for class instance' do
+ expect(C.new.method(:hello).class_comment).to eq(@class_comment)
+ end
end
# end
describe "Comment tests" do
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index d011657..0cf9739 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -10,10 +10,16 @@ def jruby?
end
+# This is a comment for module
module M
def hello; :hello_module; end
end
+# This is a comment for class
+class C
+ include M
+end
+
$o = Object.new
def $o.hello; :hello_singleton; end