I'm testing lib/pdf_helper.rb
. So i create spec/lib
directory. Then I create a file pdf_helper_spec.rb
in spec/lib
directory. As I'm testing that pdf folder should be in public folder and here is my code
require 'spec_helper'
require 'pdf_helper'
describe "Pdfhelpers" do
it "Should be in public folder" do
file = File.new ("#{Rails.root}/public/pdf")
if File.exist?(file) == 'true'
puts "Success"
else
puts"failed"
end
end
end
Am i right?? I'm new on RSpec.
expect(File).not_to exist("#{Rails.root}/public/pdf")
Will work for both files and folders.
Pathname also turns out to be fairly readable for this sort of thing.
require 'pathname'
# ...
expect(Pathname.new('file.txt')).to exist
expect(Pathname.new('file.txt')).to be_file
expect(Pathname.new('dir')).to be_directory
If you're wanting to know if a file is a directory, then you can use the File.directory?
function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With