features/step_definitions/format_steps.rb in activeadmin-0.6.6 vs features/step_definitions/format_steps.rb in activeadmin-1.0.0.pre1
- old
+ new
@@ -1,38 +1,34 @@
-CSVLib = if RUBY_VERSION =~ /^1.8/
- require 'fastercsv'
- FasterCSV
- else
- require 'csv'
- CSV
- end
+require 'csv'
Then "I should see nicely formatted datetimes" do
- page.body.should =~ /\w+ \d{1,2}, \d{4} \d{2}:\d{2}/
+ expect(page.body).to match /\w+ \d{1,2}, \d{4} \d{2}:\d{2}/
end
Then /^I should( not)? see a link to download "([^"]*)"$/ do |negate, format|
- method = negate ? :should_not : :should
- page.send method, have_css("#index_footer a", :text => format)
+ method = negate ? :to_not : :to
+ expect(page).send method, have_css("#index_footer a", text: format)
end
# Check first rows of the displayed CSV.
Then /^I should download a CSV file with "([^"]*)" separator for "([^"]*)" containing:$/ do |sep, resource_name, table|
- body = page.driver.response.body
- headers = page.response_headers
- headers['Content-Type'].should eq 'text/csv; charset=utf-8'
- headers['Content-Disposition'].should eq %{attachment; filename="#{resource_name}-#{Time.now.strftime("%Y-%m-%d")}.csv"}
+ body = page.driver.response.body
+ content_type_header, content_disposition_header = %w[Content-Type Content-Disposition].map do |header_name|
+ page.response_headers[header_name]
+ end
+ expect(content_type_header).to eq 'text/csv; charset=utf-8'
+ expect(content_disposition_header).to match /\Aattachment; filename=".+?\.csv"\z/
begin
- csv = CSVLib.parse(body, :col_sep => sep)
+ csv = CSV.parse(body, col_sep: sep)
table.raw.each_with_index do |expected_row, row_index|
expected_row.each_with_index do |expected_cell, col_index|
cell = csv.try(:[], row_index).try(:[], col_index)
if expected_cell.blank?
- cell.should be_nil
+ expect(cell).to be_nil
else
- (cell || '').should match /#{expected_cell}/
+ expect(cell || '').to match /#{expected_cell}/
end
end
end
rescue
puts "Expecting:"
@@ -46,7 +42,11 @@
Then /^I should download a CSV file for "([^"]*)" containing:$/ do |resource_name, table|
step %{I should download a CSV file with "," separator for "#{resource_name}" containing:}, table
end
Then /^the CSV file should contain "([^"]*)" in quotes$/ do |text|
- page.driver.response.body.should match /"#{text}"/
+ expect(page.driver.response.body).to match /"#{text}"/
+end
+
+Then /^the encoding of the CSV file should be "([^"]*)"$/ do |text|
+ expect(page.driver.response.body.encoding).to be Encoding.find(Encoding.aliases[text] || text)
end