rubyslim 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. data/.gitignore +7 -0
  2. data/Gemfile +3 -0
  3. data/Gemfile.lock +16 -0
  4. data/README.md +187 -0
  5. data/Rakefile +21 -0
  6. data/bin/rubyslim +10 -0
  7. data/lib/rubyslim/list_deserializer.rb +67 -0
  8. data/lib/rubyslim/list_executor.rb +12 -0
  9. data/lib/rubyslim/list_serializer.rb +43 -0
  10. data/lib/rubyslim/ruby_slim.rb +61 -0
  11. data/lib/rubyslim/slim_error.rb +3 -0
  12. data/lib/rubyslim/slim_helper_library.rb +23 -0
  13. data/lib/rubyslim/socket_service.rb +53 -0
  14. data/lib/rubyslim/statement.rb +79 -0
  15. data/lib/rubyslim/statement_executor.rb +174 -0
  16. data/lib/rubyslim/table_to_hash_converter.rb +34 -0
  17. data/lib/test_module/library_new.rb +13 -0
  18. data/lib/test_module/library_old.rb +12 -0
  19. data/lib/test_module/should_not_find_test_slim_in_here/test_slim.rb +7 -0
  20. data/lib/test_module/simple_script.rb +9 -0
  21. data/lib/test_module/test_chain.rb +5 -0
  22. data/lib/test_module/test_slim.rb +86 -0
  23. data/lib/test_module/test_slim_with_arguments.rb +23 -0
  24. data/lib/test_module/test_slim_with_no_sut.rb +5 -0
  25. data/rubyslim.gemspec +21 -0
  26. data/spec/instance_creation_spec.rb +40 -0
  27. data/spec/it8f_spec.rb +9 -0
  28. data/spec/list_deserializer_spec.rb +67 -0
  29. data/spec/list_executor_spec.rb +187 -0
  30. data/spec/list_serialzer_spec.rb +39 -0
  31. data/spec/method_invocation_spec.rb +128 -0
  32. data/spec/slim_helper_library_spec.rb +80 -0
  33. data/spec/socket_service_spec.rb +98 -0
  34. data/spec/spec_helper.rb +2 -0
  35. data/spec/statement_executor_spec.rb +50 -0
  36. data/spec/statement_spec.rb +17 -0
  37. data/spec/table_to_hash_converter_spec.rb +32 -0
  38. metadata +100 -0
@@ -0,0 +1,80 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
2
+ require 'slim_helper_library'
3
+ require 'statement_executor'
4
+
5
+ SLIM_HELPER_LIBRARY_INSTANCE_NAME = "SlimHelperLibrary"
6
+ ACTOR_INSTANCE_NAME = "scriptTableActor"
7
+
8
+ describe SlimHelperLibrary do
9
+ before() do
10
+ @executor = StatementExecutor.new
11
+ @executor.add_module("TestModule")
12
+ @executor.create(ACTOR_INSTANCE_NAME, "TestSlim", ["0"]).should == "OK"
13
+ @instance = @executor.instance(ACTOR_INSTANCE_NAME)
14
+ @helper = SlimHelperLibrary.new(@executor)
15
+ end
16
+
17
+ it "can get current scriptTableActor" do
18
+ @helper.get_fixture.should be @instance
19
+ end
20
+
21
+ it "can push and pop" do
22
+ @helper.push_fixture
23
+ @executor.create(ACTOR_INSTANCE_NAME, "TestSlim", ["1"])
24
+ @helper.get_fixture.should_not be @instance
25
+ @helper.pop_fixture
26
+ @helper.get_fixture.should be @instance
27
+ end
28
+
29
+ it "can push and pop many" do
30
+ @helper.push_fixture
31
+ @executor.create(ACTOR_INSTANCE_NAME, "TestChain", []).should == "OK"
32
+ one = @executor.instance(ACTOR_INSTANCE_NAME)
33
+ one.should_not be_nil
34
+ @helper.push_fixture
35
+
36
+ @executor.create(ACTOR_INSTANCE_NAME, "SimpleScript", [])
37
+ two = @executor.instance(ACTOR_INSTANCE_NAME)
38
+ one.should_not be two
39
+ @helper.get_fixture.should be two
40
+
41
+ @helper.pop_fixture
42
+ @helper.get_fixture.should be one
43
+
44
+ @helper.pop_fixture
45
+ @helper.get_fixture.should be @instance
46
+
47
+ end
48
+
49
+ end
50
+
51
+
52
+ #@Test
53
+ #public void testSlimHelperLibraryIsStoredInSlimExecutor() throws Exception {
54
+ # Object helperLibrary = caller.getInstance(SLIM_HELPER_LIBRARY_INSTANCE_NAME);
55
+ # assertTrue(helperLibrary instanceof SlimHelperLibrary);
56
+ #}
57
+ #
58
+ #@Test
59
+ #public void testSlimHelperLibraryHasStatementExecutor() throws Exception {
60
+ # SlimHelperLibrary helperLibrary = (SlimHelperLibrary) caller.getInstance(SLIM_HELPER_LIBRARY_INSTANCE_NAME);
61
+ # assertSame(caller, helperLibrary.getStatementExecutor());
62
+ #}
63
+ #
64
+ #@Test
65
+ #public void testSlimHelperLibraryCanPushAndPopFixture() throws Exception {
66
+ # SlimHelperLibrary helperLibrary = (SlimHelperLibrary) caller.getInstance(SLIM_HELPER_LIBRARY_INSTANCE_NAME);
67
+ # Object response = caller.create(ACTOR_INSTANCE_NAME, getTestClassName(), new Object[0]);
68
+ # Object firstActor = caller.getInstance(ACTOR_INSTANCE_NAME);
69
+ #
70
+ # helperLibrary.pushFixture();
71
+ #
72
+ # response = caller.create(ACTOR_INSTANCE_NAME, getTestClassName(), new Object[] {"1"});
73
+ # assertEquals("OK", response);
74
+ # assertNotSame(firstActor, caller.getInstance(ACTOR_INSTANCE_NAME));
75
+ #
76
+ # helperLibrary.popFixture();
77
+ #
78
+ # assertSame(firstActor, caller.getInstance(ACTOR_INSTANCE_NAME));
79
+ #}
80
+ #
@@ -0,0 +1,98 @@
1
+ require 'test/unit'
2
+ require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
3
+ require 'socket_service'
4
+
5
+ class SocketServiceTest < Test::Unit::TestCase
6
+ def setup
7
+ @port = 12345
8
+ @ss = SocketService.new()
9
+ @connections = 0
10
+ end
11
+
12
+ def testOneConnection
13
+ @ss.serve(@port) {@connections += 1}
14
+ connect(@port)
15
+ @ss.close()
16
+ assert_equal(1, @connections)
17
+ end
18
+
19
+ def testManyConnections
20
+ @ss.serve(@port) {@connections += 1}
21
+ 10.times {connect(@port)}
22
+ @ss.close()
23
+ assert_equal(10, @connections)
24
+ assert_equal(0, @ss.pendingSessions)
25
+ end
26
+
27
+ def testSocketSend
28
+ @ss.serve(@port) do |serverSocket|
29
+ serverSocket.write("hi")
30
+ end
31
+
32
+ clientSocket = TCPSocket.open("localhost", @port)
33
+ answer = clientSocket.gets
34
+ clientSocket.close
35
+ assert_equal("hi", answer)
36
+ @ss.close()
37
+ end
38
+
39
+ # TEST FREEZES!!!
40
+ # We should not be able to keep the service alive by hitting
41
+ # it with connections after we close it?
42
+ def _testCantKeepAliveByConnectingAfterClose
43
+ #set up a service that waits for a message and then dies.
44
+ @ss.serve(@port) do |serverSocket|
45
+ message = serverSocket.gets
46
+ end
47
+
48
+ #s1 is a connection to that service.
49
+ s1 = TCPSocket.open("localhost", @port)
50
+ sleep(0.1)
51
+
52
+ #now start closing the server in a separate thread. It cannot
53
+ #finish closing until s1 completes.
54
+ Thread.start {@ss.close}
55
+ sleep(0.1)
56
+
57
+ #try to connect to the dying server.
58
+ s2=nil
59
+ Thread.start {s2 = TCPSocket.open("localhost", @port)}
60
+ sleep(0.1)
61
+ assert_equal(nil, s2, "shouldn't have connected")
62
+ assert_not_equal(nil, s1, "Should have connected")
63
+
64
+ #Complete the s1 session.
65
+ s1.write("testCloseRaceCondition");
66
+ s1.close
67
+
68
+ #collect the pending s2 connection
69
+ testThread = Thread.current
70
+ @ss.serve(@port) {testThread.wakeup}
71
+ Thread.stop
72
+ assert_not_equal(nil, s2)
73
+ s2.close
74
+ @ss.close
75
+ end
76
+
77
+ def testSessionCount
78
+ @ss.serve(@port) do |serverSocket|
79
+ message = serverSocket.gets
80
+ end
81
+
82
+ s1 = nil;
83
+ Thread.start {s1 = TCPSocket.open("localhost", @port)}
84
+ sleep(0.2)
85
+ assert_equal(1, @ss.pendingSessions);
86
+ s1.write("testSessionCount");
87
+ s1.close
88
+ sleep(0.2)
89
+ assert_equal(0, @ss.pendingSessions)
90
+ @ss.close
91
+ end
92
+
93
+ def connect(port)
94
+ s = TCPSocket.open("localhost", @port)
95
+ sleep(0.1)
96
+ s.close
97
+ end
98
+ end
@@ -0,0 +1,2 @@
1
+ $: << File.expand_path(File.dirname(__FILE__) + "/../lib/rubyslim")
2
+ require 'timeout'
@@ -0,0 +1,50 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
2
+ require "statement_executor"
3
+
4
+ describe StatementExecutor do
5
+ before do
6
+ @executor = StatementExecutor.new
7
+ end
8
+
9
+ it "can split class names" do
10
+ @executor.split_class_name("a::b::c").should == ["a", "b", "c"]
11
+ end
12
+
13
+ it "can convert module names to file names" do
14
+ @executor.to_file_name("MyModuleName").should == "my_module_name"
15
+ end
16
+
17
+ it "can build the path name to a class" do
18
+ @executor.make_path_to_class("ModuleOne::ModuleTwo::MyClass").should == "module_one/module_two/my_class"
19
+ end
20
+
21
+ it "can require a class" do
22
+ @executor.add_module("MyModule")
23
+ proc = proc {@executor.require_class("MyModule::MyClass")}
24
+ proc.should raise_error(SlimError, /message:<<COULD_NOT_INVOKE_CONSTRUCTOR MyModule::MyClass failed to find in/)
25
+ end
26
+
27
+ it "can handle symbols whose values are objects" do
28
+ @executor.set_symbol("foo", OpenStruct.new(:foo => "bar"))
29
+ @executor.get_symbol("foo").foo.should == "bar"
30
+ @executor.replace_symbol("$foo").foo.should == "bar"
31
+ end
32
+
33
+ describe "accessor translation" do
34
+ class TestInstance
35
+ attr_accessor :foo
36
+ end
37
+
38
+ before(:each) do
39
+ @instance = TestInstance.new
40
+ @executor.set_instance("test_instance", @instance)
41
+ end
42
+
43
+ it "should translate setters" do
44
+ @executor.call("test_instance", "set_foo", "123")
45
+ @instance.foo.should == "123"
46
+ end
47
+
48
+ end
49
+
50
+ end
@@ -0,0 +1,17 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
2
+ require "statement"
3
+
4
+ describe Statement do
5
+ before do
6
+ @statement = Statement.new("")
7
+ end
8
+
9
+ it "can translate slim class names to ruby class names" do
10
+ @statement.slim_to_ruby_class("myPackage.MyClass").should == "MyPackage::MyClass"
11
+ @statement.slim_to_ruby_class("this.that::theOther").should == "This::That::TheOther"
12
+ end
13
+
14
+ it "can translate slim method names to ruby method names" do
15
+ @statement.slim_to_ruby_method("myMethod").should == "my_method"
16
+ end
17
+ end
@@ -0,0 +1,32 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/spec_helper")
2
+ require 'table_to_hash_converter'
3
+
4
+ def shouldNotChange(string)
5
+ TableToHashConverter.convert(string).should == string
6
+ end
7
+
8
+ describe TableToHashConverter do
9
+ [
10
+ ["some string", "not a table"],
11
+ ["<table>blah", "incomplete table"],
12
+ ["<table><tr><td>hi</td></tr></table>", "too few columns"],
13
+ ["<table><tr><td>hi</td><td>med</td><td>lo</td></tr></table>", "too many columns"]
14
+ ].each do |string, reason|
15
+ it "#{reason}: should not change '#{string}'" do
16
+ shouldNotChange(string)
17
+ end
18
+ end
19
+ end
20
+
21
+ describe TableToHashConverter do
22
+ [
23
+ ["<table><tr><td>name</td><td>bob</td></tr></table>", {:name=>"bob"}],
24
+ [" <table> <tr> <td> name </td> <td> bob </td> </tr> </table> ", {:name=>"bob"}],
25
+ ["<table><tr><td>name</td><td>bob</td></tr><tr><td>addr</td><td>here</td></tr></table>", {:name=>'bob', :addr=>'here'}],
26
+ ["<table class=\"hash_table\"><tr><td>name</td><td></td></tr></table>", {:name=>""}],
27
+ ].each do |table, hash|
28
+ it "should match #{table} to #{hash}" do
29
+ TableToHashConverter.convert(table).should == hash
30
+ end
31
+ end
32
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubyslim
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Robert C. Martin
9
+ - Doug Bradbury
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-08-09 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: 1.3.0
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: 1.3.0
31
+ description: ! " RubySliM implements the SliM protocol for the FitNesse\n acceptance
32
+ testing framework.\n"
33
+ email: unclebob@cleancoder.com
34
+ executables:
35
+ - rubyslim
36
+ extensions: []
37
+ extra_rdoc_files: []
38
+ files:
39
+ - .gitignore
40
+ - Gemfile
41
+ - Gemfile.lock
42
+ - README.md
43
+ - Rakefile
44
+ - bin/rubyslim
45
+ - lib/rubyslim/list_deserializer.rb
46
+ - lib/rubyslim/list_executor.rb
47
+ - lib/rubyslim/list_serializer.rb
48
+ - lib/rubyslim/ruby_slim.rb
49
+ - lib/rubyslim/slim_error.rb
50
+ - lib/rubyslim/slim_helper_library.rb
51
+ - lib/rubyslim/socket_service.rb
52
+ - lib/rubyslim/statement.rb
53
+ - lib/rubyslim/statement_executor.rb
54
+ - lib/rubyslim/table_to_hash_converter.rb
55
+ - lib/test_module/library_new.rb
56
+ - lib/test_module/library_old.rb
57
+ - lib/test_module/should_not_find_test_slim_in_here/test_slim.rb
58
+ - lib/test_module/simple_script.rb
59
+ - lib/test_module/test_chain.rb
60
+ - lib/test_module/test_slim.rb
61
+ - lib/test_module/test_slim_with_arguments.rb
62
+ - lib/test_module/test_slim_with_no_sut.rb
63
+ - rubyslim.gemspec
64
+ - spec/instance_creation_spec.rb
65
+ - spec/it8f_spec.rb
66
+ - spec/list_deserializer_spec.rb
67
+ - spec/list_executor_spec.rb
68
+ - spec/list_serialzer_spec.rb
69
+ - spec/method_invocation_spec.rb
70
+ - spec/slim_helper_library_spec.rb
71
+ - spec/socket_service_spec.rb
72
+ - spec/spec_helper.rb
73
+ - spec/statement_executor_spec.rb
74
+ - spec/statement_spec.rb
75
+ - spec/table_to_hash_converter_spec.rb
76
+ homepage:
77
+ licenses: []
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 1.8.25
97
+ signing_key:
98
+ specification_version: 3
99
+ summary: Ruby SliM protocol for FitNesse
100
+ test_files: []