plugins/repl/spec/repl/internal_mirror_spec.rb in redcar-0.3.2dev vs plugins/repl/spec/repl/internal_mirror_spec.rb in redcar-0.3.3
- old
+ new
@@ -34,10 +34,11 @@
>> $internal_repl_test = 707
=> 707
>> $internal_repl_test = 909
RUBY
@mirror.commit(text.chomp)
+ text.chomp
end
def result_test_text2
(<<-RUBY).chomp
# Redcar REPL
@@ -47,11 +48,25 @@
>> $internal_repl_test = 909
=> 909
>>
RUBY
end
+
+
+ def commit_no_input
+ text = <<-RUBY
+# Redcar REPL
+>>
+RUBY
+ @mirror.commit(text)
+ end
+
+ def prompt
+ "# Redcar REPL\n\n"
+ end
+
describe "with no history" do
it "should exist" do
@mirror.should be_exist
end
@@ -74,11 +89,22 @@
describe "when executing" do
it "should execute committed text" do
commit_test_text1
$internal_repl_test.should == 707
end
-
+
+ it "should allow committing nothing as the first command" do
+ commit_no_input
+ @mirror.read.should == "# Redcar REPL\n\n>> \n=> nil\n>> "
+ end
+
+ it "should allow committing nothing as an xth command" do
+ committed = commit_test_text2
+ @mirror.commit committed + "\n>> "
+ @mirror.read.should == "# Redcar REPL\n\n>> $internal_repl_test = 909\n=> 909\n>> \n=> nil\n>> "
+ end
+
it "should emit changed event when text is executed" do
commit_test_text1
@changed_event.should be_true
end
@@ -86,11 +112,11 @@
commit_test_text1
@mirror.read.should == result_test_text1
end
it "should display errors" do
- @mirror.commit(">> nil.foo")
+ @mirror.commit(prompt + ">> nil.foo")
@mirror.read.should == (<<-RUBY).chomp
# Redcar REPL
>> nil.foo
x> NoMethodError: undefined method `foo' for nil:NilClass
@@ -128,17 +154,18 @@
end
end
describe "when executing" do
it "should execute inside a main object" do
- @mirror.commit(">> self")
- @mirror.results.last.should == ["main", false]
+ @mirror.commit(prompt + ">> self")
+ @mirror.history.last.should == ["self", [["", :output], ["main", :result]] ]
end
it "should persist local variables" do
- @mirror.commit(">> a = 13")
- @mirror.commit(">> a")
- @mirror.results.last.should == ["13", false]
+ sent = prompt + ">> a = 13"
+ @mirror.commit(sent)
+ @mirror.commit(sent + "\n>> a")
+ @mirror.history.last.should == ["a", [["", :output], ["13", :result]] ]
end
end
end
end