You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to test the output from the Terminal and wrote this snippet that narrows down what I am trying to do. https://gist.github.com/1474931. Would you be able to tell me if I am testing HighLine incorrectly?
I see that calling Readline.readline(question, true) results in a nil return value. At that point of execution, question is defined as @output.string which is equal to the empty string "". Now, if I'm testing the output text, why am I getting an error relating to the input?
I am running Ruby 1.9.2-p290 with the latest version of highline on the latest version of Mac OS X.
Incidentally, I tried the same test on a Windows 7 machine with Ruby 1.9.3-p0 and got the following results:
C:\Users\ddyba\Scripts\exhausted_input>ruby highline_test.rb
Run options:
# Running tests:
E
Finished tests in 0.005000s, 200.0000 tests/s, 0.0000 assertions/s.
1) Error:
test_ask_question_returns_prompt(HighLineTest):
NoMethodError: private method `puts' called for nil:NilClass
C:/Users/ddyba/.pik/rubies/Ruby-193-p0/lib/ruby/gems/1.9.1/gems/highline-1.6.8/lib/highline.rb:608:in `say'
C:/Users/ddyba/.pik/rubies/Ruby-193-p0/lib/ruby/gems/1.9.1/gems/highline-1.6.8/lib/highline.rb:245:in `ask'
highline_test.rb:7:in `ask_question'
highline_test.rb:15:in `setup'
1 tests, 0 assertions, 0 failures, 1 errors, 0 skips
C:\Users\ddyba\Scripts\exhausted_input>
The text was updated successfully, but these errors were encountered:
This isn't a bug in HighLine and it isn't related to Readline (which isn't used in this example).
The issue is that you are passing an empty StringIO for HighLine to read content from. That returns nil, just as an exhausted IO object would:
>> StringIO.new.gets
=> nil
We just need to provide some answer for HighLine to read. I realize you aren't using it in the test, but HighLine reads for input before we ever get to your assertion.
Here's how I got your test to run:
require 'test/unit'
require 'stringio'
require 'highline'
def ask_question(input = $stdin, output = $stdout)
highline = HighLine.new(input, output)
highline.ask("How are you?")
end
class HighlineTest < Test::Unit::TestCase
def setup
@input = StringIO.new("some answer")
@output = StringIO.new
ask_question(@input, @output)
end
def test_ask_question_returns_prompt
assert_equal "How are you?\n", @output.string
end
end
I am trying to test the output from the Terminal and wrote this snippet that narrows down what I am trying to do. https://gist.github.com/1474931. Would you be able to tell me if I am testing HighLine incorrectly?
I see that calling
Readline.readline(question, true)
results in anil
return value. At that point of execution,question
is defined as@output.string
which is equal to the empty string""
. Now, if I'm testing the output text, why am I getting an error relating to the input?I am running Ruby 1.9.2-p290 with the latest version of highline on the latest version of Mac OS X.
Incidentally, I tried the same test on a Windows 7 machine with Ruby 1.9.3-p0 and got the following results:
The text was updated successfully, but these errors were encountered: