From a0e6433f5acdd06ae948feddf31e492d829fff57 Mon Sep 17 00:00:00 2001 From: Dennis Collinson <dennis.collective@gmail.com> Date: Fri, 16 Mar 2012 17:24:51 -0700 Subject: [PATCH] test multiple file upload in cucumber --- features/step_definitions/trumpeter_steps.rb | 16 +++++++++++++--- features/trumpeter.feature | 17 ++++++++++------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/features/step_definitions/trumpeter_steps.rb b/features/step_definitions/trumpeter_steps.rb index 378d30aeb2..999ef806bc 100644 --- a/features/step_definitions/trumpeter_steps.rb +++ b/features/step_definitions/trumpeter_steps.rb @@ -41,13 +41,23 @@ Then /^"([^"]*)" should be a (limited|public) post in my stream$/ do |post_text, end When /^I upload a fixture picture with filename "([^"]*)"$/ do |file_name| + orig_photo_count = all(".photos img").size + within ".new_photo" do attach_file "photo[user_file]", Rails.root.join("spec", "fixtures", file_name) + wait_until { all(".photos img").size == orig_photo_count + 1 } end - @image_source = find(".photos img")["src"] + @image_sources ||= {} + @image_sources[file_name] = all(".photos img").last["src"] + @image_sources[file_name].should be_present +end + +Then /^"([^"]*)" should have the "([^"]*)" picture$/ do |post_text, file_name| + image = find_post_by_text(post_text).find(".photo_attachments img[src='#{@image_sources[file_name]}']") + image.should be_present end -Then /^"([^"]*)" should have my photo$/ do |status_text| - find_post_by_text(status_text).find(".photo_attachments img")["src"].should == @image_source +Then /^"([^"]*)" should have (\d+) pictures$/ do |post_text, number_of_pictures| + find_post_by_text(post_text).all(".photo_attachments img").size.should == number_of_pictures.to_i end \ No newline at end of file diff --git a/features/trumpeter.feature b/features/trumpeter.feature index eac163fc59..f33cc68186 100644 --- a/features/trumpeter.feature +++ b/features/trumpeter.feature @@ -5,13 +5,15 @@ Feature: Creating a new post And I sign in as "bob@bob.bob" And I trumpet - Scenario: Posting a public message - And I write "Rectangles are awesome" + Scenario: Posting a public message with a photo + And I write "I love RMS" When I select "Public" in my aspects dropdown + And I upload a fixture picture with filename "button.gif" When I press "Share" When I go to "/stream" - Then I should see "Rectangles are awesome" as the first post in my stream - And "Rectangles are awesome" should be a public post in my stream + Then I should see "I love RMS" as the first post in my stream + And "I love RMS" should be a public post in my stream + Then "I love RMS" should have the "button.gif" picture Scenario: Posting to Aspects And I write "This is super skrunkle" @@ -29,9 +31,10 @@ Feature: Creating a new post And I go to "/stream" Then I follow "Alice Smith" - Scenario: Uploading a photo - When I write "check out this picture" + Scenario: Uploading multiple photos + When I write "check out these pictures" + And I upload a fixture picture with filename "button.gif" And I upload a fixture picture with filename "button.gif" And I press "Share" And I go to "/stream" - Then "check out this picture" should have my photo + Then "check out these pictures" should have 2 pictures -- GitLab