2012-11-23 2 views
0

양식에서 텍스트 영역의 내용을 테스트하기 위해 올바른 구문을 사용하려고합니다.텍스트 영역의 내용을 테스트하기 위해 webrat을 얻는 방법

나는

response.should have_selector('textarea') 

와 텍스트 영역의 존재를 확인할 수 있지만 contains 메소드는 응답에 보이는 텍스트를 확인하기 위해 나타납니다. textarea의 내용을 검사하는 capybara 메소드가 있지만, WebBat에있는 모든 것으로 보이는 Capybara에 대한 기존의 커다란 세트를 작업하고 있습니다. have_field와 같은 Capybara 메소드를 사용하려고하면 다음과 같이 계속됩니다. 오류 :

RSpec::Expectations::ExpectationNotMetError Exception: expected field "textarea" to return something 

나는 다음과 같은 일을 예를 발견했습니다

response.should have_selector('textarea', :content => 'blah') 

을하지만 이상하게도이 계속 디버거 원인과 나는 해결책으로 효과적으로 테스트 할 수 없었다 아직.

많은 여기

감사 올바른 접근 방법에 대한 모든 팁이나 조언은 내가 디버거

(rdb:1) p response.should have_selector('textarea#article_body_and_extended', :content => text) 
/usr/local/lib/ruby/gems/1.9.1/gems/ruby-debug19-0.11.6/cli/ruby-debug/interface.rb:70:in `printf' 
/usr/local/lib/ruby/gems/1.9.1/gems/ruby-debug19-0.11.6/cli/ruby-debug/interface.rb:70:in `print' 
/usr/local/lib/ruby/gems/1.9.1/gems/ruby-debug19-0.11.6/cli/ruby-debug/processor.rb:375:in `print' 
/usr/local/lib/ruby/gems/1.9.1/gems/ruby-debug19-0.11.6/cli/ruby-debug/command.rb:165:in `print' 
/usr/local/lib/ruby/gems/1.9.1/gems/ruby-debug19-0.11.6/cli/ruby-debug/command.rb:183:in `rescue in debug_eval' 
/usr/local/lib/ruby/gems/1.9.1/gems/ruby-debug19-0.11.6/cli/ruby-debug/command.rb:173:in `debug_eval' 
/usr/local/lib/ruby/gems/1.9.1/gems/ruby-debug19-0.11.6/cli/ruby-debug/commands/eval.rb:47:in `block in execute' 
/usr/local/lib/ruby/gems/1.9.1/gems/ruby-debug19-0.11.6/cli/ruby-debug/commands/eval.rb:19:in `run_with_binding' 
/usr/local/lib/ruby/gems/1.9.1/gems/ruby-debug19-0.11.6/cli/ruby-debug/commands/eval.rb:46:in `execute' 
/usr/local/lib/ruby/gems/1.9.1/gems/ruby-debug19-0.11.6/cli/ruby-debug/processor.rb:275:in `one_cmd' 
/usr/local/lib/ruby/gems/1.9.1/gems/ruby-debug19-0.11.6/cli/ruby-debug/processor.rb:261:in `block (2 levels) in process_commands' 
/usr/local/lib/ruby/gems/1.9.1/gems/ruby-debug19-0.11.6/cli/ruby-debug/processor.rb:260:in `each' 
/usr/local/lib/ruby/gems/1.9.1/gems/ruby-debug19-0.11.6/cli/ruby-debug/processor.rb:260:in `block in process_commands' 
/usr/local/lib/ruby/gems/1.9.1/gems/ruby-debug19-0.11.6/cli/ruby-debug/processor.rb:253:in `catch' 
/usr/local/lib/ruby/gems/1.9.1/gems/ruby-debug19-0.11.6/cli/ruby-debug/processor.rb:253:in `process_commands' 
/usr/local/lib/ruby/gems/1.9.1/gems/ruby-debug19-0.11.6/cli/ruby-debug/processor.rb:173:in `at_line' 
(eval):5:in `block in at_line' 
<internal:prelude>:10:in `synchronize' 
(eval):3:in `at_line' 
/usr/local/lib/ruby/gems/1.9.1/gems/ruby-debug-base19-0.11.25/lib/ruby-debug-base.rb:55:in `at_line' 
/home/ubuntu/Documents/hw5/typo/spec/controllers/admin/content_controller_spec.rb:509:in `block (4 levels) in <top (required)>' 
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example.rb:113:in `instance_eval' 
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example.rb:113:in `block in run' 
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example.rb:253:in `with_around_each_hooks' 
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example.rb:110:in `run' 
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:378:in `block in run_examples' 
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:374:in `map' 
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:374:in `run_examples' 
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:360:in `run' 
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:361:in `block in run' 
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:361:in `map' 
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:361:in `run' 
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:361:in `block in run' 
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:361:in `map' 
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:361:in `run' 
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:28:in `block (2 levels) in run' 
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:28:in `map' 
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:28:in `block in run' 
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/reporter.rb:34:in `report' 
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:25:in `run' 
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:69:in `run' 
/usr/local/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:8:in `block in autorun'F 

에서 테스트를받을 스택 트레이스의 다음 디버거는 계속 검사가 실패

text = @article.body + @article_for_merging.body + "\n&lt;<!--more-->&gt;\n" [email protected] 
    debugger 
    response.should have_selector('textarea#article_body_and_extended', :content => text) 

비록 내가 응답 본문에 정규식을 할 때 나는 일치를 얻는다

(rdb:1) p text 
"A content with several datasomething we will merge&lt;<!--more-->&gt;extended content for fun" 
(rdb:1) p response.body =~ text 
TypeError Exception: type mismatch: String given 
(rdb:1) p response.body =~ /text/ 
218 

내가 원하는 것은 텍스트 영역의 실제 내용을 끌어내는 방법입니다 ... 컨트롤러 사양 대신 모델 사양을 작성해야한다는 의미가 있지만 ...

+0

내가 디버거에서 테스트하려고 얻을 스택 트레이스를 추가 ... 이동하고 나중에 다시 와서 유혹 : 그러나 어떤 작업을 수행하는 것은 이것이다 –

답변

0

그래서 나는이 일을하는 것을 포기했습니다. 올바른 구문을 다음과 같이 추적했다고 생각합니다.

response.should have_selector('textarea', :name => "article[body_and_extended]",:content => text) 

여기서 예상되는 내용으로 텍스트를 설정했습니다. 나는 텍스트 영역에있는 텍스트를 정확하게 가지고 있는지 확인하는 데 시간을 할애하지만 인코딩 문제 또는 그 밖의 것이 어쩌면 작동하지 않을 수 있습니다.

text = @article.body + @article_for_merging.body + "\n&lt;!--more--&gt;\n" [email protected][email protected]_for_merging.extended 
    position = response.body =~ /#{Regexp.quote(text)}/ 
    position.should_not be_nil 

그래서 난

관련 문제