Commit 89c5452

mo khan <mo@mokhan.ca>
2016-05-06 00:27:15
add search spec and just js driver.
1 parent cbfc8fd
Changed files (5)
features
spec
features
support
features/step_definitions/gym_steps.rb
@@ -3,7 +3,7 @@ When /^the user is on the gyms page$/ do
   @subject.visit_page
 end
 
-And /^There are (\d) gyms$/ do |n|
+And /^There are (.*) gyms$/ do |n|
   @gyms = n.to_i.times.map do
     FactoryGirl.create(:gym)
   end
features/support/env.rb
@@ -47,7 +47,7 @@ DatabaseCleaner.strategy = :transaction
 #   end
 #
 
-#Capybara.default_driver = :poltergeist
+Capybara.javascript_driver = :poltergeist
 # Possible values are :truncation and :transaction
 # The :transaction strategy is faster, but might give you threading problems.
 # See https://github.com/cucumber/cucumber-rails/blob/master/features/choose_javascript_database_strategy.feature
features/finding_a_gym.feature
@@ -8,9 +8,10 @@ Feature: Finding a gym
     When the user is on the gyms page
     Then it lists all gyms
 
+  @javascript
   Scenario: Find a gym in a city
     Given the user is logged in
-    And There are 3 gyms
+    And There are 10 gyms
     When the user is on the gyms page
     And they search for a city
     Then it lists all gyms
spec/features/gyms_spec.rb
@@ -26,8 +26,22 @@ feature "Gyms", type: :feature do
       expect(subject).to have_content(calgary_gym.name)
       expect(subject).to have_content(edmonton_gym.name)
     end
+
+    describe "search" do
+      let!(:other_calgary_gym) { create(:gym, name: 'world health', location: create(:calgary)) }
+
+      it 'returns gyms that match the search criteria', js: true do
+        subject.visit_page
+        subject.search("sait")
+
+        expect(subject).to be_on_page
+        expect(subject).to have_content(calgary_gym.name)
+        expect(subject).to have_no_content(other_calgary_gym.name)
+      end
+    end
   end
 
+
   feature "adding a gym" do
     subject { NewGymPage.new }
 
spec/support/pages/gyms_page.rb
@@ -8,7 +8,7 @@ class GymsPage < PageModel
   def search(query)
     within "#search-form" do
       fill_in "q", with: query
-      #page.execute_script("$('form#search-form').submit()")
+      page.execute_script("$('form#search-form').submit()")
     end
   end
 end