2012-07-24 4 views
1

현재 "Page Object"패턴을 사용하기 위해 전체 오이 테스트를 리팩토링하고 있지만 RSpec matcher를 사용하는 데 많은 문제가 있습니다. .Cucumber/Capybara - "Page Object"패턴을 사용하는 RSpec matcher 사용

다음과 내가 가진 기존의 단계가 될 때 :

Then /^I should (not)?see the following alerts:$/ do |negate, alerts| 
    expectation = negate ? :should_not : :should 

    @alert_reporting_panel = AlertReportingPanel.new(Capybara.current_session) 
    @alert_reporting_panel.verify_contents expectation, alerts 
end 

그리고 내 패널 개체는 다음과 같습니다 :

Then /^I should (not)?see the following alerts:$/ do |negate, alerts| 
    expectation = negate ? :should_not : :should 

    within(ALERT_TABLE_ID) do 
    alerts.hashes.each do |alert| 
     page.send(expectation, have_content(alert["Original ID"])) 
    end 
    end 
end 

내 리팩토링 단계는 불행하게도

class AlertReportingPanel 
    def initialize(session) 
    @session = session 
    end 

    def verify_contents(expectation, alerts) 
    @session.within(ALERT_TABLE_ID) do 
     alerts.hashes.each do |alert| 
     @session.send(expectation, have_content(alert["Original ID"])) 
     end 
    end 
    end 
end 

, 나는 undefined method 'have_contents' for #<AlertReportingPanel:0x3f0faf8> (NoMethodError)를 얻을 수 .
require 'rspec'을 클래스 상단에 추가하려고 시도했으며 메서드를 정규화하여 시도 했으므로 : Capybara::RSpecMatchers::HaveMatcher.have_content, 그러나 단지 uninitialized constant Capybara::RSpecMatchers (NameError)이 표시됩니다.

저는 Ruby를 처음 접했고이 문제를 수정하는 것이 쉽다는 것을 확신합니다 ...하지만 나는 그것을 스스로 해결할 수없는 것 같습니다.

도와주세요. 고맙습니다.

답변

3

이것은 잠시 뒤 였으므로 지금 쯤은 답을 얻을 수있을 것이라고 추측합니다. 그러나 여기에 있습니다.

* have_content * 등을 가져오고 액세스 할 수 있도록 필요한 모듈을 포함해야합니다. 그래서 패널 개체의 모습 :

class AlertReportingPanel 
    include Capybara::DSL 
    include Capybara::Node::Matchers 
    include RSpec::Matchers 

    def initialize... etc 
+0

감사합니다. 지연에 대해 유감스럽게 생각하고, 나는 루비/오이를 사용하지 않은 다른 프로젝트에서 바빴다. –

1

대신 당신이

SitePrism 내가 좀 편견이야 사용하여 시도 할 수 있습니다 자신의 페이지 개체 시스템을 작성하는 (나는 보석 썼다)하지만, 인생을 더 쉽게 만들 수도 있습니다 너를 위해서.

+0

좋은데 ... 간다! –

관련 문제