Permalink
Browse files

supports first half of Slim 0.3 - reusing instances

  • Loading branch information...
1 parent fe175c8 commit cc7b482cb0e676c8fc0ba9d3183721dee74bff51 @dougbradbury dougbradbury committed Feb 1, 2011
View
@@ -1,7 +1,7 @@
.rakeTasks
-RubySlim.iml
-RubySlim.ipr
-RubySlim.iws
+*.iml
+*.ipr
+*.iws
.DS_Store
.idea
View
@@ -18,7 +18,7 @@ def run(port)
end
def serve_ruby_slim(socket)
- socket.puts("Slim -- V0.2");
+ socket.puts("Slim -- V0.3");
said_bye = false
while !said_bye
length = socket.read(6).to_i
@@ -0,0 +1,3 @@
+class SlimHelperLibrary
+
+end
@@ -17,10 +17,14 @@ def library?(instance_name)
def create(instance_name, class_name, constructor_arguments)
begin
- instance = construct_instance(replace_symbol(class_name), replace_symbols(constructor_arguments))
- if library?(instance_name)
- @libraries << instance
+ instance = replace_symbol(class_name)
+ if instance.is_a?(String)
+ instance = construct_instance(instance, replace_symbols(constructor_arguments))
+ if library?(instance_name)
+ @libraries << instance
+ end
end
+
@instances[instance_name] = instance
"OK"
rescue SlimError => e
@@ -96,7 +100,8 @@ def to_file_name(module_name)
end
def send_message_to_instance(instance, method, args)
- instance.send(method, *replace_tables_with_hashes(replace_symbols(args)))
+ symbols = replace_symbols(args)
+ instance.send(method, *replace_tables_with_hashes(symbols))
end
def call(instance_name, method_name, *args)
@@ -131,11 +136,18 @@ def get_symbol(name)
@symbols[name]
end
+ def acquire_symbol(symbol_text)
+ symbol = get_symbol(symbol_text[1..-1])
+ symbol = symbol_text if symbol.nil?
+ symbol
+ end
+
def replace_symbol(item)
+ match = item.match(/\A\$\w*\z/)
+ return acquire_symbol(match[0]) if match
+
item.gsub(/\$\w*/) do |match|
- symbol = get_symbol(match[1..-1])
- symbol = match if symbol.nil?
- symbol
+ acquire_symbol(match)
end
end
@@ -1,3 +1,5 @@
+require 'ostruct'
+
module TestModule
class SystemUnderTest
def sut_method
@@ -7,12 +9,15 @@ def sut_method
class TestSlim
attr_reader :sut
- def initialize
+ attr_accessor :string
+ def initialize(generation = 0)
+ @generation = generation
@sut = SystemUnderTest.new
+ @string = "string"
end
def return_string
- "string"
+ @string
end
def returnString #Should not ever be called.
@@ -47,5 +52,33 @@ def utf8
"Espa\357\277\275ol"
end
+ def create_test_slim_with_string(string)
+ slim = TestSlim.new(@generation + 1)
+ slim.string = string
+ slim
+ end
+
+ def new_with_string(string)
+ s = TestSlim.new
+ s.string = string
+ s
+ end
+
+ def echo_object(method, string)
+ OpenStruct.new(method.to_sym => string)
+ end
+
+ def call_on(method, object)
+ object.send(method.to_sym)
+ end
+
+# def is_same(other)
+# self === other
+# end
+#
+# def get_string_from_other other
+# other.get_string_arg
+# end
+
end
end
View
@@ -1,11 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<module type="RUBY_MODULE" version="4">
- <component name="NewModuleRootManager" inherit-compiler-output="true">
- <exclude-output />
- <content url="file://$MODULE_DIR$" />
- <orderEntry type="jdk" jdkName="Ruby SDK 1.8.7 (1)" jdkType="RUBY_SDK" />
- <orderEntry type="sourceFolder" forTests="false" />
- <orderEntry type="library" scope="PROVIDED" name="[gem] rspec (v1.3.1, /Users/dougbradbury/.rvm/gems/ruby-1.8.7-p302/gems/rspec-1.3.1)" level="application" />
- </component>
-</module>
-
@@ -29,8 +29,8 @@
end
it "can't create an instance with the wrong number of arguments" do
- result = @caller.create("x", "TestModule::TestSlim", ["noSuchArgument"])
- result.should include(Statement::EXCEPTION_TAG + "message:<<COULD_NOT_INVOKE_CONSTRUCTOR TestModule::TestSlim[1]>>")
+ result = @caller.create("x", "TestModule::TestSlim", ["1", "noSuchArgument"])
+ result.should include(Statement::EXCEPTION_TAG + "message:<<COULD_NOT_INVOKE_CONSTRUCTOR TestModule::TestSlim[2]>>")
end
it "can't create an instance if there is no class" do
@@ -172,4 +172,17 @@ def check_results expectations
check_results "id2"=>"OK"
end
+ it "can use a fixture method that returns a fixture object" do
+ add_statement "id1", "callAndAssign", "object", "test_slim", "echo_object", "let_me_see", "Boogaloo"
+ add_statement "id2", "call", "test_slim", "call_on", "let_me_see", "$object"
+ check_results "id2" => "Boogaloo"
+ end
+
+ it "can use an instance that was stored as a symbol" do
+ add_statement "id1", "callAndAssign", "test_slim_instance", "test_slim", "create_test_slim_with_string", "Boogaloo"
+ add_statement "m2", "make", "test_slim", "$test_slim_instance"
+ check_results "m2" => "OK"
+
+ end
+
end
@@ -0,0 +1,14 @@
+require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
+require 'slim_helper_library'
+
+describe SlimHelperLibrary do
+ before() do
+ @helper = SlimHelperLibrary.new
+ end
+
+ it "should push a fixture" do
+ pending
+
+ end
+
+end
@@ -23,4 +23,10 @@
proc = proc {@executor.require_class("MyModule::MyClass")}
proc.should raise_error(SlimError, /message:<<COULD_NOT_INVOKE_CONSTRUCTOR MyModule::MyClass failed to find in/)
end
+
+ it "can handle symbols whose values are objects" do
+ @executor.set_symbol("foo", OpenStruct.new(:foo => "bar"))
+ @executor.get_symbol("foo").foo.should == "bar"
+ @executor.replace_symbol("$foo").foo.should == "bar"
+ end
end

0 comments on commit cc7b482

Please sign in to comment.