tomekcieslar / circle

0 stars 0 forks source link

Feature specs #10

Open stevo opened 6 years ago

stevo commented 6 years ago

spec/features/progress_summary_spec.rb

require 'rails_helper'

RSpec.describe 'Showing progress summary' do
  scenario do
    behavior 'User submits valid progress checklist url for given level' do
      allow(GetGistMarkdown).to receive(:call) {
        <<~MARKDOWN
          ## Rails 
            [ ] Whatever
        MARKDOWN
      }

      visit '/'
      fill_in 'Gist URL', with: 'https://gist.github.com/stevo/abc'
      select 'independent', from: 'Level'
      click_on 'Submit'

      expect(page).to have_content('Total: 2/5')
    end
  end
end

# GetGistMarkdown - empty class
# ...
stevo commented 6 years ago

rvm install "ruby-2.5.1"

stevo commented 6 years ago

expect(page).to have_selector('.guests-header__heading', text: 'Michael Jordan')

page.within('div', text: 'header text') do
   expect(page).to have_selector('li', text: 'cośtam')
end
stevo commented 6 years ago
RSpec::Matchers.define :have_reservation do |**args|
  match do |page|
    reservation_div = page.find('div.guests-booking', text: "$#{args[:price].to_f}")
    expect(reservation_div).to have_content(args[:details])
    expect(reservation_div).to have_content(args[:checkin_date])
    expect(reservation_div).to have_content(args[:checkout_date])
  end

  failure_message do
    "Expected page to have reservation for '#{args[:details]}' from '#{args[:checkin_date]}' to " \
    "#{args[:checkout_date]}' for '#{args[:price]}', but it did not"
  end
end
stevo commented 6 years ago

expect(page).to have_list('Item 1', 'item 2')

# spec/support/matchers/have_list.rb
RSpec::Matchers.define :have_list do |*expected_list_items|
  match do |page|
   list = page.find('ul')
   expected_list_items.each do |list_item|
    expect(list).to have_selector('li', text: list_item)
   end
  end  
end
stevo commented 6 years ago
[5] pry(#<RSpec::ExampleGroups::GlobalSearch>)> have_link('create').description
=> "have visible link \"create\""
[6] pry(#<RSpec::ExampleGroups::GlobalSearch>)> have_content('create').description
=> "text \"create\""
[7] pry(#<RSpec::ExampleGroups::GlobalSearch>)> 'Expected list to include item with [visible link "create"][text "create"], but it was not found'
stevo commented 6 years ago

# expected_list_item -> list_item_expectation(s)

# list_item_expectation.responds_to?(:matches)
# if yes then .any?
# if no then .has_selector?

page.has_selector?('li', text: 'cośtam')

match do |page|
@missing_elements = []

list_items = list.find_all('li')
unless list_items.any? { |list_item| expected_list_item.matches?(list_item) }
@missing_elements << expected_list_item.description
end

@missing_elements.blank?
end

failure_message do
  "Nie znaleziono elementu #{@missing_elements.join(', ')}"
end