Skip to content

Instantly share code, notes, and snippets.

@somethvictory
Created February 3, 2017 08:13
Show Gist options
  • Save somethvictory/aa5d6074609b54db171773d96d1a2223 to your computer and use it in GitHub Desktop.
Save somethvictory/aa5d6074609b54db171773d96d1a2223 to your computer and use it in GitHub Desktop.
Sample feature spec with RSpec Capybara.
feature 'Color Scheme' do
given(:development) { create(:development) }
given(:user) { create(:user, :admin) }
given!(:color_scheme) { create(:color_scheme, development: development, name: FFaker::Name.name, price: 13660)}
given(:other_development){ create(:development) }
given!(:image) { create(:image, development: development) }
before do
login_as(user)
end
feature 'Create' do
scenario 'valid', js: true do
visit new_admin_development_color_scheme_path(development)
fill_in 'Name', with: 'Color Scheme Name'
fill_in 'Code', with: 'color1'
fill_in 'Price', with: 13660
fill_in 'Description', with: FFaker::Lorem.paragraph
find("a[data-association='color_scheme_image']").trigger('click')
select_image(image, from: '.image-picker')
click_button 'Create Color scheme'
expect(page).to have_content('Color Scheme is successfully created')
last_color_scheme = ColorScheme.unscoped.last
expect(last_color_scheme.code).to eq('color1')
expect(last_color_scheme.name).to eq('Color Scheme Name')
expect(last_color_scheme.price).to eq(13660)
end
scenario 'invalid' do
visit new_admin_development_color_scheme_path(development)
click_button 'Create Color scheme'
expect(page).to have_content("can't be blank")
end
scenario 'existing name in different development' do
visit new_admin_development_color_scheme_path(other_development)
fill_in 'Name', with: color_scheme.name
fill_in 'Code', with: 'color1'
fill_in 'Price', with: 8400
fill_in 'Description', with: FFaker::Lorem.paragraph
click_button 'Create Color scheme'
expect(page).to have_content('Color Scheme is successfully created')
expect(page).to have_content(color_scheme.name)
end
scenario 'existing name in the same development' do
visit new_admin_development_color_scheme_path(development)
fill_in 'Name', with: color_scheme.name
fill_in 'Code', with: 'color1'
fill_in 'Price', with: 13660
fill_in 'Description', with: FFaker::Lorem.paragraph
click_button 'Create Color scheme'
expect(page).to have_content('has already been taken')
end
end
feature 'Edit' do
before do
visit edit_admin_development_color_scheme_path(development, color_scheme)
end
scenario 'valid', js: true do
fill_in 'Name', with: 'Color Scheme Name'
fill_in 'Price', with: 0
fill_in 'Description', with: FFaker::Lorem.paragraph
find("a[data-association='color_scheme_image']").trigger('click')
upload_to_gallery 'spec/supports/default_logo.png', with: '.image-picker'
click_button 'Update Color scheme'
expect(page).to have_content('Color Scheme is successfully updated')
expect(page).to have_content('Color Scheme Name')
end
scenario 'invalid' do
fill_in 'Name', with: ''
click_button 'Update Color scheme'
expect(page).to have_content("can't be blank")
expect(page).to have_content(color_scheme.description)
end
end
feature 'Delete' do
before do
visit admin_development_color_scheme_path(development, color_scheme)
end
scenario 'User delete color scheme' do
click_link 'Delete'
expect(page).to have_content('Color Scheme is successfully deleted')
expect(page).not_to have_content(color_scheme.name)
expect(page.current_path).to eq(admin_development_color_schemes_path(development))
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment