Skip to content

Commit

Permalink
added specs, fixed a few underlying issues with endless.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Edgar committed Aug 2, 2010
1 parent 8bcbe88 commit f0e3770
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 5 deletions.
10 changes: 9 additions & 1 deletion lib/seamless.rb
@@ -1,2 +1,10 @@
require 'polyglot'
require 'seamless/endless'
require 'seamless/endless'

class EndlessRubyPolyglotLoader
def self.load(filename, options = nil, &block)
Endless.load(filename)
end
end

Polyglot.register("rbe", EndlessRubyPolyglotLoader)
4 changes: 2 additions & 2 deletions lib/seamless/endless.rb
Expand Up @@ -187,8 +187,8 @@ def load(filename,wrap=false)
pre += "/" unless pre.empty? || pre[-2,1] == '/'
path = pre + filename
if File.exist? path
code = File.read(path)
Tempfile.open(filename) do |f|
code = File.read(path) + "\n" # force newline at end of file
Tempfile.open(File.basename(filename)) do |f|
preprocess code, filename, f
f.rewind
return ::Kernel::load(f.path, wrap)
Expand Down
11 changes: 11 additions & 0 deletions spec/examples/class.rbe
@@ -0,0 +1,11 @@
class HelloThing
def initialize(name)
@name = name

def run_ten_times()
x = 0
result = []
while x < 10
x += 1
result << "Hello, #{@name}"
result
3 changes: 3 additions & 0 deletions spec/examples/no_newline_at_end.rbe
@@ -0,0 +1,3 @@
class HelloWorlder
def times_two
return "Hello, world! Hello, world!"
8 changes: 8 additions & 0 deletions spec/examples/rescue.rbe
@@ -0,0 +1,8 @@
module Rescueable
class Rescued
class << self
def a_method
begin
raise "hai"
rescue
return 5
2 changes: 2 additions & 0 deletions spec/examples/simple.rbe
@@ -0,0 +1,2 @@
def testing_method(arg)
arg.to_s + ", " + arg.to_s
24 changes: 22 additions & 2 deletions spec/seamless_spec.rb
@@ -1,7 +1,27 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')

describe "Seamless" do
it "fails" do
fail "hey buddy, you should probably rename this file and start specing for real"
def load_example(name)
require File.expand_path(File.dirname(__FILE__) + "/examples/#{name}")
end

it 'loads a simple method in endless form' do
load_example 'simple'
testing_method(50).should == '50, 50'
end

it 'loads a class in endless form' do
load_example 'class'
HelloThing.new('mike').run_ten_times.should == ['Hello, mike'] * 10
end

it 'loads endlessly formed rescues' do
load_example 'rescue'
Rescueable::Rescued.a_method.should == 5
end

it 'loads endless files with no newline at the end' do
load_example 'no_newline_at_end'
HelloWorlder.new.times_two.should == "Hello, world! Hello, world!"
end
end
1 change: 1 addition & 0 deletions spec/spec_helper.rb
@@ -1,5 +1,6 @@
$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'rubygems'
require 'seamless'
require 'spec'
require 'spec/autorun'
Expand Down

0 comments on commit f0e3770

Please sign in to comment.