Best place in spec/ for integration responses? - ruby-on-rails

I have some integration points where I want to test various responses - where do you think should I store these artifacts in my spec/ directory of my rails application?

In the past I've created a test/resources or spec/resources directory for other test/spec related files. That seems to keep it clear that it's some sort of other file used only for testing.

you could just create a spec/fixtures dir and stick em in there.

Related

Rails folder structure

I have a script which is using rspec tests for automation of the rails app. I don't want to put the file "automation.rb" in the spec folder or in the lib folder (don't want a gem for this code).
My question is: Can we have custom folders in addition to the standard ones in the rails directory structure.
Eg. a folder like automation in the root directory of rails app.
Yes, you can have any number of custom folders within your app structure.
The thing to be aware of here, is that if you're going to use code from these folders (why would you have them otherwise?), you'll have to load it.
To not mess things up much, you can add these folders under /app directory - anything defined there is automatically loaded in all environments.
As to scripts - indeed, you can just store them under the scripts folder in root directory - it's a common practice (at least I've seen it used in projects I have worked on).

Where to store dummy products images while developing Rails 4 website

I am working on my first RoR website. You can consider it as a shop with products.
I use Ruby 2.0, Rails 4.0, Cucumber for integration testing and RSpec for unit-testing.
Also I use FactoryGirl for populating database with test data.
Apart of automatic testing I would like to be able to open website on local server and see some dummy products with description and images.
Here is the question: where to store products images used in development environment?
Here are my thoughts:
I do not want to use paperclip yet.
I cannot store dummy images in assets or public because they will be
deployed to production.
I do not know how to access /test/factories/images or any other
directory except of assets and public.
I do not want to store images in database.
I want deployable solution in case I would need to populate test
website from CI.
It seems to be a common Rails question: where to store dummy test resources accessible to client?
However the only solution I found is to use paperclip. But I do not have upload yet. I just want to have 100 images for dummy products
You cud use your db seed file for this and your tester should then only need to run rake db:seed to setup the dummy files.
If you create an directory inside /db and call it seed_files or something you prefer. Then in your /db/seeds.rb you cud write some code that moves those files into /public/images/product_images. /public/images/product_images should also be in git ignore.
When you do this you cud have an name pattern and anchor them to some product records in your database. You cud also put your seed script in an unless Rails.env.production? block if you will use your seed file in production but not seed the dummy images.
You can put your images in a subdirectory of assets such as assets/dummy and then add assets/dummy to the .gitignore file (assuming you're using git) so that the dummy directory is not deployable.

Cucumber to test Email Parsing?

this is my first stackoverflow question.
I am building an app that gets posted an email from SendGrid, which I then want to parse in a delayed job.
My concern is how do I QA this. I have been reading about Cucumber and that sounds like a good solution but I can't figure out the end to end test flow.
Here's where I am so far.
I want to have a large list of TXT files that include various types of email body's
I then iterate through each txt file, and make sure that when passed to a method in my lib directory /mailingjob.rb, that what is returned matches something defined in cucumber.
So what I have so far is something like:
expected = File.open('???/mail1.txt', 'r') do |f|
f.read
end
That's where I'm starting. So if you can, please help me understand the following:
Where should all these TXT files be located in the rails project directory?
One e2e example showing how to grab a local text file, pass it to a method in the /lib directory, and then make sure what is returned equals what is set for that file path.
Thank you thank you for any help you can provide
I would probably store these files somewhere in your test or spec directory (depending on what testing framework you use; you mentioned Cucumber, which I'm not super familiar with, but I think it uses a directory called features). Really, you could put them anywhere you want, but some subdirectory of your test directory makes sense.
If you're not familiar with testing with Cucumber, I recommend Railscast episode 155 and episode 159 to get you started. To answer your direct question, you would read the email from the text file as such
email_text = File.read("#{Rails.root}/test/path/to/email.txt")
Rails.root always refers to the root directory for your project, and makes it easy to build paths to other files or folders.

Where do you place documents belonging to a Rails app project?

For every project it's like having two parts: the Rails application and then all documents and pictures related to it.
I wonder how you organize them both.
Do you put everything under the same project root folder and apply Git on that folder or don't you protect your documents with Git at all?
Then, what if the docs are too sensitive or only for owners of that project. Then I probably should't have it under the same folder right?
How have you structured both your Rails code and belonging business documents?
Share your solutions!
If you're deploying with capistrano, as a lot of Rails apps are, the standard solution seems to be to keep these sorts of assets within the shared folder, and then get cap to symlink them into the application at the point of deploy.

Can/should directories for test frameworks be consolidated into a top-level directory (a la vendor/plugins)?

For some reason, I find it really irksome that the files for each testing framework (rspec, test::unit, cucumber, etc.) live in a separate folder in the top level of my app. Is there a strong reason these directories should be scattered about instead of consolidated like gems/plugins in the vendor directory?
If there isn't an actual reason for the way it is, would it be kosher to consolidate these directories into a top-level "test" directory, containing subdirectories for each of the testing frameworks alongside fixture data, etc.? Has anyone else ever been driven bonkers this (and maybe already hacked together a quick'n'easy way of updating the necessary paths to get this to work)?
I for one would welcome this change.
Personally I use RSpec and Cucumber at the same time and I'm torn whether or not to put the fixtures in the features/support/fixtures directory (I create it myself) or spec/fixtures. What if I use this fixture in features and in spec tests too?! [overly emotional] Why won't somebody think of the fixtures!!
Definitely. A top-level test directory with the subdirectories of features, specs, fixtures and whatever else you need.
Great question!

Resources