Skip to content

Commit 96aa4cb

Browse files
authored
Merge pull request #202 from sh19910711/patch/0036/raise-before-app
Use first binding when there is no application binding
2 parents 7b4aac3 + 62b7332 commit 96aa4cb

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/web_console/session.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def from(storage)
4343
def initialize(bindings)
4444
@id = SecureRandom.hex(16)
4545
@bindings = Array(bindings)
46-
@evaluator = Evaluator.new(initial_binding)
46+
@evaluator = Evaluator.new(application_binding || @bindings.first)
4747

4848
store_into_memory
4949
end
@@ -64,7 +64,7 @@ def switch_binding_to(index)
6464

6565
private
6666

67-
def initial_binding
67+
def application_binding
6868
@bindings.find { |b| b.eval('__FILE__').to_s.start_with?(Rails.root.to_s) }
6969
end
7070

test/web_console/session_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ def initialize(line)
3939
assert_equal session.eval('__FILE__'), "=> \"#{__FILE__}\"\n"
4040
end
4141

42+
test 'use first binding if no application bindings' do
43+
binding = Object.new
44+
binding.expects(:eval).with('__FILE__').returns 'framework'
45+
binding.expects(:eval).with('called?').returns 'yes'
46+
47+
session = Session.new(binding)
48+
assert_equal session.eval('called?'), "=> \"yes\"\n"
49+
end
50+
4251
test '#from can create session from a single binding' do
4352
saved_line, saved_binding = __LINE__, binding
4453
Thread.current[:__web_console_binding] = saved_binding

0 commit comments

Comments
 (0)