2014-04-26 5 views
1

이 스 니펫 뒤에 어떤 일이 발생했는지 알고 싶습니다.이 rspec 스 니펫을 구현하는 방법

Ruby가이 구문을 어떻게 구현합니까?

feature "Course" do DO_SOMETHING end 

scenario "A Course without name should not be accepted" do 
end 

루비에서
feature "Course" do 

    let(:school) {School.make!} 

    context "Logged in" do 
    before(:each) do 
     switch_to_subdomain(school) 
    end 

    context "In the new course form" do 
     before(:each) do 
     click_link("Courses") 
     click_link("New course") 
     end 

     scenario "New course" do    
     end 

     scenario "A Course without name should not be accepted" do 
     end 

     scenario "A new course should not be created if there is another one with the same name in the same school" do 
     end 
    end 
    end 
end 

답변

0

, 당신은 다음 중 하나 yield를 사용하여 호출 할 수있는 메소드의 마지막 매개 변수로 블록을 통과하거나 처리 할 수 ​​있습니다 좀 구체적인 방향이나 예를주십시오 괄호는 루비에서 선택 사항이기 때문에 명시 적 변수로, 또한 등

def scenario(name) 
    puts name 
    if block_given? 
    yield 
    end 
end 

def feature(name, &block) 
    puts name 
    if block_given? 
    scenario("called from feature", &block) 
    end 
end 

scenario("test") do puts "this" end 
# => test 
# => this 

feature("test") do puts "this" end 
# => test 
# => called from feature 
# => this 

주위를 이동, 당신은이 구문을 수신을 삭제할 수 있습니다 :

scenario "test" do 
    puts "this" 
end 
# => test 
# => this 

feature "test" do 
    puts "this" 
end 
# => test 
# => called from feature 
# => this 
관련 문제