diff options
author | Jun Aruga <jaruga@redhat.com> | 2017-05-31 12:02:51 +0200 |
---|---|---|
committer | Jun Aruga <jaruga@redhat.com> | 2017-05-31 19:04:14 +0200 |
commit | a4e02e622d381fa654f9f5e9710a673d58776128 (patch) | |
tree | 98237b180f7f8a8a64165fa7c51caa300c22d68c /spec/method_source | |
parent | 0cc6cc8e15d08880585e8cb0c54e13c3cf937c54 (diff) | |
download | method_source-a4e02e622d381fa654f9f5e9710a673d58776128.tar.gz |
Replace Bacon to RSpec 3.
Because Bacon stopped the development.
Diffstat (limited to 'spec/method_source')
-rw-r--r-- | spec/method_source/code_helpers_spec.rb | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/spec/method_source/code_helpers_spec.rb b/spec/method_source/code_helpers_spec.rb new file mode 100644 index 0000000..287ff89 --- /dev/null +++ b/spec/method_source/code_helpers_spec.rb @@ -0,0 +1,43 @@ +require 'spec_helper' + +describe MethodSource::CodeHelpers do + before do + @tester = Object.new.extend(MethodSource::CodeHelpers) + end + + [ + ["p = '", "'"], + ["def", "a", "(); end"], + ["p = <<FOO", "lots", "and", "lots of", "foo", "FOO"], + ["[", ":lets,", "'list',", "[/nested/", "], things ]"], + ["abc =~ /hello", "/"], + ["issue = %W/", "343/"], + ["pouts(<<HI, 'foo", "bar", "HI", "baz')"], + ["=begin", "no-one uses this syntax anymore...", "=end"], + ["puts 1, 2,", "3"], + ["puts 'hello'\\", "'world'"] + ].each do |lines| + it "should not raise an error on broken lines: #{lines.join("\\n")}" do + 1.upto(lines.size - 1) do |i| + expect(@tester.complete_expression?(lines[0...i].join("\n") + "\n")).to be_falsy + end + expect(@tester.complete_expression?(lines.join("\n"))).to be_truthy + end + end + + [ + ["end"], + ["puts )("], + ["1 1"], + ["puts :"] + ] + (RbConfig::CONFIG['ruby_install_name'] == 'rbx' ? [] : [ + ["def", "method(1"], # in this case the syntax error is "expecting ')'". + ["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 + expect { + @tester.complete_expression?(foo.join("\n")) + }.to raise_error(SyntaxError) + end + end +end |