2017-05-10 1 views
0

나는 오이에서이 시나리오를 쓰기 :/카피 바라가

Then(/^the following drawers should be present on the page$/) do |table| 

    value = Array.new 
    value = "#{table}" 
    stats = page.all(:css,'.radionav__panel-item').map(&:text) 
expect(value).to contain_exactly(stats) 
end 

아래

Then the following drawers should be present on the page 
     |Stations | 
     |Categories| 
     |Schedules | 
     |My Radio | 

내 단계 정의

있습니다 ["Stations", "Categories", "Schedules", "My Radio"]

value을 위해 가지고 :

,536,913 나는이 결과를 가지고 stats 인쇄
|Stations | 
|Categories| 
|Schedules | 
|My Radio | 

내가 모두 일치하려고는 난 그냥 내가 페이지에서 가져온 텍스트에 오이 기능 파일의 테이블 요소 텍스트를 일치시킬

Then the following drawers should be present on the page # features/step_def 
initions/radio_nav_steps.rb:14 
     stats : ["Stations", "Categories", "Schedules", "My Radio"] 
     | Stations | 
     | Categories | 
     | Schedules | 
     | My Radio | 
     expected a collection that can be converted to an array with `#to_ary` or 
`#to_a`, but got "\n | \e[32m Stations \e[0m\e[0m |\e[0m\n | \e[32m Cat 
egories\e[0m\e[0m |\e[0m\n | \e[32m Schedules \e[0m\e[0m |\e[0m\n | \e[32m 
    My Radio \e[0m\e[0m |\e[0m\n" (RSpec::Expectations::ExpectationNotMetError) 
     ./features/step_definitions/radio_nav_steps.rb:22:in `/^the following draw 
ers should be present on the page$/' 
     features/radio_nav.feature:34:in `Then the following drawers should be pre 
sent on the page' 

Failing Scenarios: 
cucumber features/radio_nav.feature:33 # Scenario: As a user I should see all th 
e drawers 

말하는 오류가 발생했습니다.

답변

0

이 코드는 나를 위해 작동 :

Then(/^the following drawers should be present on the page$/) do |table| 
    stats = page.all(:css,'.radionav__panel-item').map(&:text) 
    data = table.hashes 
    begin 
    data.each do|row| 
     row.each do |key, value| 
     if stats.include? value 
     else 
      puts "element not found" 
     end 
     end 
    end 
    end 
end 
0

문자열을 배열로 변환해야합니다.

이 같은 시도 뭔가를, 나는 그 이스케이프 시퀀스 무엇인지 확실하지 않다하더라도 :

value = table.lines.map{ |l| l.match(/\|(.*)\|/)[1].strip } 
0

테이블이 오이 데이터 테이블로 전달되는 단계 오이에 테이블을 전달합니다. 이것은 raw을 호출하여 배열로 변환 할 수 있습니다.

Then(/^the following drawers should be present on the page$/) do |table| 
    stats = page.all(:css,'.radionav__panel-item').map(&:text) 
    expect(table.raw.flatten).to contain_exactly(stats) 
end 
관련 문제