Integration testing is a logical extension of unit testing. In its simplest form, two units that have already been tested are combined into a component and the interface between them is tested.
The purpose of integration testing is to verify the functional, performance, and reliability between the modules that are integrated.
Each component at lower hierarchy is tested individually and then the components that rely upon these components are tested.
In Hybrid Integration Testing, we exploit the advantages of Top-down and Bottom-up approaches. As the name suggests, we make use of both the Integration techniques.
class ShopperInteractionsTest < ActionDispatch::IntegrationTest
test "place order and check orders admin" do
shopper = login_as users(:user)
admin = login_as users(:administrator)
product = products(:rails_book)
shopper.post line_items_path, line_item: { product_id: product.id }
shopper.follow_redirect!
assert_equal root_path, shopper.path
order_params = {
name: "Chris Kottom",
address: "My house",
email: "chris@example.com",
pay_type: "Credit Card"
}
assert_difference "Order.count" do
shopper.post orders_path, order: order_params
end
shopper.follow_redirect!
assert_equal root_path, shopper.path
order = Order.last
admin.get orders_path
admin.assert_select "#orders #order_#{ order.id }" do
admin.assert_select "a[href=?]", order_path(order.id)
end
end
end
RSpec.describe HomeController do
describe "contact form" do
before { visit '/' }
context "with valid message" do
it "sends the letter" do
within("#section6") do
fill_in "contact_message_name", with: "Sergiy"
fill_in "contact_message_email", with: 'sergey.kukunin@gmail.com'
select "Just Saying Hi", :from => "contact_message_subject"
fill_in "contact_message_body", with: "Glad to meet you"
end
expect { click_on "SEND" }.to change { ActionMailer::Base.deliveries.count }.by(1)
expect(page).to have_content("Thank you for contacting us.")
end
end
end
describe "licenses" do
it "shows all licenses" do
visit licenses_path
expect(page).to have_selector "table", count: 2
expect(page).to have_selector "table:nth-child(1) tbody tr", count: 2
expect(page).to have_selector "table:nth-child(1) thead", text: 'CA'
end
end
end
gem 'capybara'
gem 'poltergeist'
require 'capybara/poltergeist'
require 'capybara/rspec'
Capybara.javascript_driver = :poltergeist
visit('/projects')
visit(post_comments_path(post))
More info: https://gist.github.com/zhengjia/428105
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
fill_in('First Name', :with => 'John') fill_in('Password', :with => 'Seekrit') fill_in('Description', :with => 'Really Long Text…') choose('A Radio Button') check('A Checkbox') uncheck('A Checkbox') attach_file('Image', '/path/to/image.jpg') select('Option', :from => 'Select Box')
within("//li[@id='employee']") do
fill_in 'Name', :with => 'Jimmy'
end
within(:css, "li#employee") do
fill_in 'Name', :with => 'Jimmy'
end
within_fieldset('Employee') do
fill_in 'Name', :with => 'Jimmy'
end
within_table('Employee') do
fill_in 'Name', :with => 'Jimmy'
end
page.has_xpath?('//table/tr')
page.has_css?('table tr.foo')
page.has_content?('foo')
page.should have_xpath('//table/tr')
page.should have_css('table tr.foo')
page.should have_content('foo')
page.should have_no_content('foo')
find_field('First Name').value
find_link('Hello').visible?
find_button('Send').click
find('//table/tr').click
locate("//*[@id='overlay'").find("//h1").click
all('a').each { |a| a[:href] }
result = page.evaluate_script('4 + 4');
save_and_open_page
within(:css, 'ul li') { ... }
find(:css, 'ul li').text
locate(:css, 'input#name').value
Capybara.default_selector = :css
within('ul li') { ... }
find('ul li').text
locate('input#name').value