Skip to content

Instantly share code, notes, and snippets.

@jccarbonfive
Last active December 11, 2015 11:08
Show Gist options
  • Save jccarbonfive/4591747 to your computer and use it in GitHub Desktop.
Save jccarbonfive/4591747 to your computer and use it in GitHub Desktop.
require 'spec_helper'
describe 'Importing accounts' do
context 'given a CSV file of accounts' do
before do
visit '/'
within '#new_accounts' do
attach_file 'File', Rails.root.join('spec', 'fixtures', 'accounts.csv')
click_button 'Import'
end
end
it 'imports each account' do
expect(page).to have_content('3 accounts imported')
end
end
end
alice checking 100
bob savings 50
sam savings 200
$ rspec spec/requests/importing_accounts_spec.rb
1) Importing accounts given a CSV file of accounts imports each account
Failure/Error: visit '/'
ActionController::RoutingError:
No route matches [GET] "/"
Sample::Application.routes.draw do
resources :accounts, only: [:index, :create]
root to: 'accounts#index'
end
= form_for :accounts, url: accounts_path, html: { id: 'new_accounts', multipart: true } do |form|
= form.label :file
= form.file_field :file
= form.submit 'Import'
class AccountsController < ApplicationController
def index
end
def create
@imported = Account.import params[:accounts][:file]
redirect_to accounts_path,
notice: "#{@imported} accounts imported"
end
end
$ rspec spec/requests/importing_accounts_spec.rb
F
Failures:
1) Importing accounts given a CSV file of accounts imports each account
Failure/Error: click_button 'Import'
NoMethodError:
undefined method `import' for #<Class:0x007ffddc82eda8>
require 'spec_helper'
describe Account do
describe 'importing' do
context 'given a file of accounts' do
before do
file = double 'accounts file'
account_importer = double 'account importer'
account_importer
.stub(:import)
.with(file)
.and_return(3)
@imported = Account.import file, account_importer
end
it 'returns the total number of accounts imported' do
expect(@imported).to eq(3)
end
end
end
end
$ rspec spec/models/account_spec.rb
F
Failures:
1) Account importing given a file of accounts returns the total number of accounts imported
Failure/Error: @imported = Account.import file, account_importer
NoMethodError:
undefined method `import' for #<Class:0x007fe574fac4c0>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment