????Chris Zetter??FutureLearn?????????????????????????????????С??????????????????????????????????Cucumber?滻?RSpec????????????д??????
?????????????????????????????????????????????????FutureLearn??????????1??????????????д????????????????????Щ?1?????????????????????????????????????????
???????????????Cucumber
????Cucumber???????????д??????????ù??????????????????????????????????????????????????????????д???????????????????
Feature: Enrolment
Scenario: Enrolling in a course
Given there is a course
And I am logged in as a learner
When I enrol on a course
Then the course should appear in 'my courses'
???????????????Cucumber????????????????????±?д?????ü????У?????д????????????????????Cucumber???Щ??????????????????????????????????RSpec????????Cucumber??ζ??????????????????????Σ??????????DSLs????????????????????????????????л???????????????????????????Cucumber???????????????????Ruby?????????????????????????????????????
??????д?????RSpec features
??????????????????????????????????????Cucumber???
?????????????????RSpec features?????Cucumber?????????????????????????
feature 'Enrolment' do
scenario 'Enrolling in a course' do
course = FactoryGirl.create(:course)
learner = FactoryGirl.create(:learner)
login_as learner
visit course_path(course)
find('.join').click
expect(page).to have_content('Thanks for joining!')
visit '/'
expect(page).to have_main_header('My Courses')
expect(page).to have_content(course.full_title)
end
end
?????????????????ú???????????????便???????Щ????????????????????Arrange?? Act?? Assert????Cucumber????????’Given’??’When’??’Then’????Щ?????????????????????Щ?????????????????????????Щ?????????????????????????????????????Щ???????????????????
????????????????????????????д?????????????????????????????????????????????????????????????β????????????????????Cucumber???????????Щ????????????????????ɡ?
feature 'Enrolment' do
scenario 'Enrolling in a course' do
given_there_is_a_course
and_i_am_logged_in_as_a_learner
when_i_enrol_on_a_course
then_the_course_should_appear_in_my_courses
end
def given_there_is_a_course
@course = FactoryGirl.create(:course)
end
def and_i_am_logged_in_as_a_learner
@learner = FactoryGirl.create(:learner)
login_as @learner
end
def when_i_enrol_on_a_course
visit course_path(@course)
find('.join').click
expect(page).to have_content('Thanks for joining!')
end
def then_the_course_should_appear_in_my_courses
visit '/'
expect(page).to have_main_header('My Courses')
expect(page).to have_content(@course.full_title)
end
end
?????????кη???
??????????????????Cucumber?????????????????д??????????RSpec features??????д??????????????????Cucumber????????????????ò????????????д???????
????????????????????????????????features????????????????и????????????????????ò????????????????????д???feature?μ????scenario????????????????д????á?