System tests with ruby (rspec maybe) [closed] - ruby-on-rails

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Is there any way to do system testing with ruby?
I'm trying to test a multithreaded service (distributed in warbled in jar file) with having just SOAP inputs and STDOUT as outputs, and that's all what I have. I need to create custom, not trivial scenarios, and looking for the best way to do that. Google does not help with that.
System testing of software or hardware is testing conducted on a complete, integrated system to evaluate the system's compliance with its specified requirements. System testing falls within the scope of black box testing, and as such, should require no knowledge of the inner design of the code or logic.
UPDATE:
I suppose I had to say that I have 3 separate components with interaction between them. And this service, im talking about is like proxy for other 2. And if I just start to write code, I need to repeat lots of functionality. So yes I'm looking for some framework to mock both services and ability to create multiple of scenarios.

Yes, Ruby is excellent for system or application level tests.
I would recommend Cucumber. Cucumber is a Ruby application which lets you define an external DSL (Domain Specific Language) specific to your environment, and then use that DSL to write and run tests.
Here's the example Cucumber test (from the Cucumber home page):
Feature: Addition
In order to avoid silly mistakes
As a math idiot
I want to be told the sum of two numbers
Scenario: Add two numbers
Given I have entered 50 into the calculator
And I have entered 70 into the calculator
When I press add
Then the result should be 120 on the screen
That's written in the mini-language you define. These "step definitions" are in Ruby, using Cucumber's internal DSL:
Given /I have entered (.*) into the calculator/ do |n|
calculator = calculator.new
calculator.push(n.to_i)
end
These step definitions are what tie your custom external DSL to the code or system under test. This example tests a simple Ruby class, but Cucumber is fine for integrated testing of libraries or applications.
Keeping DRY is not a problem. Step definitions can call other step definitions, and since they are written in Ruby, you can easily put shared code into modules or classes for use by your step definitions.
All that's left to answer is whether Ruby and its available libraries have the capabilities needed to drive your test environment. Ruby is a good "glue" language, able to easily run other programs. It also has a fairly good set of libraries (called "Ruby gems") available, including several which can do soap (e.g. savon). Libraries are available for working with XML and interfacing with various protocols (HTTP, FTP, etc.).

Related

Testing tools available for Rails application [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am newbie to rails testing I google and found few testing framework like
1. rspec
2. cucumber
3. capybara
4. factorygirl
5. jasmin
and default rails has its own testing tools.
I need to know what to use and when to use for
functional, unit and
integration testing
And how we can automate the testing so before deploy it will run all our test cases?
Definitely read the Rails guides on testing best practices; there's a ton of books, blog posts, and Youtube videos out there on how to test. But part of your question has been a particular pain point for me so I'll give a brief answer here too: Which of these complex tools are worth using, and for what kinds of tests?
The Rails community is huge on tests, but personally I think that it's possible to go too far, focus too much energy on your test suite at the expense of actually writing code. Some high-profile folks have even advocated that developers try out not writing tests once or twice, just so that we can get firsthand experience with the effect it has on our code quality, number of bugs, etc. (Spoiler: quality goes down, bugs go up, customer satisfaction goes down. But it's different for you to learn this firsthand than for me to just tell you.)
So my personal testing habits for Rails apps are:
I prefer Minitest over Rspec. The former encourages plain, straightforward unit tests; the latter encourages verbose specs and a larger testing infrastructure. Minitest (or Rspec) is more or less "global" to your test suite, in that all of your specs will be written using that same framework. Which is good because there's less tools to manage and less to learn.
FactoryGirl is useful in quickly setting up a specific database scenario for a given test. I use it in model, controller, and integration tests.
Capybara is a framework for writing highly readable end-user acceptance / integration tests. It's appealing but it's easy to overuse, leading to verbose tests that get brittle and hard to maintain. I write (thorough) controller specs first, then write judicious integration tests afterwards.
Cucumber is a layer on top of Capybara (for integration tests) or for any other kind of test; it lets you write out your tests in a human-readable format and forces you to think in terms of acceptance tests. But it gets easy to become too verbose, and on the tiny-team projects I've worked on so far, I haven't yet found it useful. I avoid it.
Jasmine is like Rspec for Javascript: a language for writing readable and well-organized specs of your JS code. This may be useful if you have tons of custom JS code / logic, but I haven't yet used it or envied it.
Model unit tests: I write at least one unit test for each custom method.
Controller unit tests: I write at least one unit test for each logical path available to each controller action, and enable rendering views so the template generation gets exercised here too.
Integration / acceptance tests: I go light on these, only adding very minimal paths to cover the essential use cases of the website. I find most bugs aren't caught at this level; the controller tests catch a lot more, since they render every single view template and execute every bit of model logic that the user can possibly trigger.

using rails for a very thin application [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I've been working on a large website with Ruby on Rails for more than 2 years now and found it really convenient and easy to code a web application or service. Now I want to build a really thin web service: no DB, no front end 1-2 controllers with 2-3 actions each.
When I invoke rails new, it sort of "scaffolding" a large application structure, there is any way to get the default large structure replaced for a small service suitable structure with rails? (btw, If you think I don't need to use rails for such a project you're welcome to explain why. )
I was just going to upvote some comments, but we try not to answer in comments, so I'll try to synthesize the relevant points:
Rails' infrastructure is designed to accomodate a fairly complex app, and is probably overkill for the sort of simple app you're talking about building. This matters because Rails embraces Convention Over Configuration, and the conventions are geared toward larger apps.
Here's a couple of examples (not an exhaustive list):
Rails separates routes into their own file, with individual controller classes for interacting with each type of resource. If you have only a handful of pages in your app, this can be more structure than you need.
Although you can tell it not to, Rails assumes by default that you want to use ActiveRecord (and that you have a database for it to talk to). It also assumes you'll want model classes, and that there's both enough of them and they're complex enough that they need their own directory of individual files.
The Rails Asset Pipeline is great for dealing with lots of complicated assets that require extensive preprocessing. It's also kind of a pain in the ass.
There are a number of Ruby-based microframeworks that are likely better suited to the sort of app you describe. Sinatra is probably the most widely used. It makes few assumptions and is consequently lightweight, allowing you to establish whatever design patterns you want in your app. There are also bunch of others that might be worth considering.

Tool suggestions for specification by example where analysts - not developers - write the tests?

We are looking to initiate a bdd-style approach, inspired by Gojko Adzic's specification by example. Implementation is in java and devs are already writing junit tests.
Key requirement is that specifications (acceptance tests) can be written, read and maintained by non-developers. The project will run as an agile team - so it's fine if devs have to instrument the specs. However, I don't want developers, testers or domain experts having to read or write something that looks like code.
So far I've looked at FitNesse, Concordion and various others (e.g. Spock). I've rejected spock and similar tools because they target developers as the primary audience. FitNesse seems to meet most of the requirements.
Concordion is probably current favourite however: specs looks cleaner and simpler.
So my question (actually three):
Any suggestions for other tools I should look at?
Has anyone been successful with using concordion (or another tool) in this way?
Is concordion still actively developed/supported? Difficult to tell from website and most related SO questions are several years old.
Thanks.
I've worked with a number of teams implementing Specification by Example with Concordion. We train our whole team up to write Concordion specifications in HTML. Only a small subset of HTML is required, so we can train a newbie in about 30 minutes. Typically we have the testers writing the HTML specification, with the BA or Scrum Master sometimes writing them.
We've used Eclipse (Web Page Editor) for editing the HTML. This works well, except that Concordion requires valid XHTML, and Eclipse does not allow HTML to be validated as XHTML. This mostly shows with <br> tags being used rather than <br/>. We cover this off in training. We also train the whole team in the use of source control. By using Eclipse, we have a single user interface for editing and source control. We also find that having the team using the same IDE is a step on the journey to a cross-functional team.
I know of another team where the BA is writing the specifications using a Mac-based HTML editor.
Concordion is actively maintained, with rapid responses on the mailing list (Yahoo) and the issues list. The Concordion codebase is stable. The active development over the last year or so has focussed on the extension mechanism, allowing users to add commands and listeners (eg. for capturing screenshots on test failure).
Also take a look at Cucumber and JBehave, both of which allow specifications to be written in plain text.
If you choose to use FitNesse, it may also be worth looking at Slim, which sits behind FitNesse in place of Fit. It provides slightly different table formats to Fit, and I've found it suits BDD much better.
Just to update the topic, you can also consider jnario.

What are the coolest Ruby on Rails features, why choose it? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Before I asked this question I had a look through the search results for 'Ruby on Rails' here on SO. Couldn't find much, but the following (found on this page) amused me
Personally, I started using .html, moved onto php, tried ruby (hated it), discovered Python / DJango.. and have been happy ever since.
Now here's the deal. I have no personal intention of learning Ruby on Rails just yet, but it's the topic of a group presentation I am to do at the Uni (and my mates chose the RoR subject). People with a grudge against students asking homework-type questions should leave immediately.
This question is for RoR people who find it great. I hope to find those that claim RoR is the best (authors of the breathtaking testimonials to be found at RoR website). What makes RoR so outstanding? What would you like the youths of today to find out about it just before they leave the Uni with a degree. Try suggesting something that could root in their minds and perhaps navigate them the RoR way after leaving Uni.
Your answers will not only help my presentation, but could be the source of enlightenment for many.
ActiveRecord's dynamic finders:
Person.find_by_name_and_company_id('Jorge Luis Borges', 42)
rjs, writing javascript in ruby:
page['element_id'].insert_html :bottom, :partial => 'comment'
ActiveRecord's scoping
class Shirt < ActiveRecord::Base
named_scope :red, :conditions => {:color => 'red'}
named_scope :dry_clean_only, :joins => :washing_instructions, :conditions => ['washing_instructions.dry_clean_only = ?', true]
end
calling Shirt.red will query the db with the "color = 'red'" condition
the cool part, is that if you combine more than one scope eg:
Shirt.red.dry_clean_only
it will build just one query, with all the conditions and joins necessary to satisfy both scopes.
ActiveRecord's Migrations, being able to manage db structure and data using active record, just like in the app's code, with minimal sql usage.
Tools are about solving problems. It doesn't matter whether you're talking about the tools in a wood worker's shop or a programmer's. What impressed me about Rails (and still does) is that it was extracted from framework used to build real-world web apps and has repeatedly been improved by people who extended or changed it after using it to build real-world web apps. It was no mere academic exercise.
Some of the specific problems it addressed:
Getting started quickly. If you are looking to get a web application underway quickly, what better choices could you have than a framework that specifies an existing directory structure (one based on MVC), with lots of code generators, and choices already pre-made for you as to components like JavaScript library, testing support, ORM, etc. You may not agree with all the choices but you can assume them and have something that will work for 80% or more of projects and swap out something later if you have a preference.
Long term maintainability. Migrations give you ways to move data forward as your code changes, something that happens in any real-world application, yet most frameworks do not account for that at all. Separating all of the parts of your application into a directory hierarchy already setup with areas for testing, database, configuration, etc. again aids the long term maintenance of your project.
Reduced human error. Configuration files give you extra opportunities for human error. Logical conventions, once learned can avoid mistakes like the classic mistyped file name or class name in a configuration file error.
Recognition of different modes of development. Rails has built in support for the idea of having a different set of settings for development vs. test vs. production. Real apps have this too, but often the framework around them doesn't accommodate it and you end up having to swap configuration files in and out to achieve the same effect (see human error above).
Good practices. Several things I've mentioned above embrace and encourage good programming practices (MVC, standardized project layout, etc.) but Rails is often explicit in encouraging them and not just implicit. For evidence of that you need look no further than its built in support for test driven development.
I blogged in detail about why I love Rails three years ago, but for me for number one cool feature is that it makes developing web applications easy and fun.
To name a few items:
Large developer community (not saying that python doesn't)
Convention over configuration rocks
Can be used with JRuby/Warbler to make rails run on Java Application servers. Very important when trying to drag Enterprise into the 21st century (Django can be used with Jython to work with application servers, but is less mature).
MVC framework helps keep your application structured.
Scaffolding and generators to get your project moving.
Rails doesn't try to be the only way to do web applications, that's not the intent. It fulfills a specific set of needs.
This isn't a comparison against Python - it's a general list of things I like.
I write a lot less code than I would in Java
... And the code I do right is very readable and maintainable
I very rarely need to think where some code lives or how to handle a common task - it just has its place (e.g. migrations are built in)
You don't end up using lot of different technologies on one project (Java, EJB, Hibernate, JSP, SQL DDL, Ant, XML, taglibs)
Interpreted rather than compiled saves you lots of development time
One of the main reasons for me is that it puts fun back into web programming.
Suddenly things become simple and within reach. you don't need months of code crunching and
don't need tons of code written. you can do some pretty amazing things with just a few lines.
And it feels good :)
Honestly, I like the design of Django more then rails, but I like ruby more then python. Its a personal thing, because I know plenty of people who feel the opposite way, but I find ruby to be one of the most elegant languages I have ever used.
My main motivation for using Rails is ruby. I touched a lot of languages before I found ruby and I never felt I was any good in any of them. When I met ruby everything just made sense. It's a beautiful language; Easy to learn but hard to master.
I use rails because it suits my needs as a webdeveloper and is very feature rich.

What are some interesting projects to solve in Erlang for learning purposes? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I recently discovered Erlang and am now working my way through a couple of tutorials. By now I'm looking forward to actually implement something as a hobby project. I'm not really interested in yet another chat server. I would like to code something more interesting (yes I'm aware that this is a rather fuzzy term) which is also manageable, so I can finish it in my spare time.
Any suggestions?
Edit: The project should preferably highlight Erlang's strenghts (concurrency, distributed).
Build a distributed system that searches twitter feeds in real time and allows anyone to perform searches from a web front end.
Build a distributed file system. Implement distributed B*Trees or B+Trees as the base of this file system. Do it in erlang.
Build a distributed key value store on top of the distributed file system built in step 2.
Build a distributed web index (to be used by a distributed web search engine) on top of the key value store.
Build a distributed linker. Advanced build automation offers remote agent processing for distributed builds and/or distributed processing.
Build a MMORPG backend that relies on distributed storage of the game/player state and distributed processing of user requests.
For something for yourself, consider writing a simple server; something that, for example, services date/time requests or -- a little fancier -- an HTTP daemon that serves only static content.
The best part of Erlang is the way it handles concurrency; exercize that.
Project Euler, for sure.
Some things from my copious ToDo list that would both be good learning exercises and helpful to the erlang community at large:
Profile all the available Key/Value stores:
Write a library for testing insert, lookup, delete, search times for a variety of K/V stores
Create a benchmark suite people can run
Make it work with ets, dets, proplists, gb_trees, dict, orddict, redblack trees, bdb, tokyocabinet, ...
Produce pretty graphs
Make it easy to update, contribute to and run on anyone's machine
write a new io_lib:format routine that uses named parameters:
io_lib:nformat("Hi there ~{name}s~n.", [{name, "Bob"}]).
This is useful for internationalisation if the position of parameters changes when the language of the format string changes.
Extend erl -make (make.erl)
Allow adding code paths (so that you don't need to do erl -pa LibraryPath -make)
Compile/load behaviour modules before modules that implement those behaviours
Handle hierarchal modules correctly (output path in particular)
This doesn't exactly answer your question, but if you are looking for an interesting free, open-source project that is written in Erlang, you should definitely check out CouchDB. From the website:
Apache CouchDB is a distributed,
fault-tolerant and schema-free
document-oriented database accessible
via a RESTful HTTP/JSON API. Among
other features, it provides robust,
incremental replication with
bi-directional conflict detection and
resolution, and is queryable and
indexable using a table-oriented view
engine with JavaScript acting as the
default view definition language.
CouchDB is written in Erlang, but can
be easily accessed from any
environment that provides means to
make HTTP requests. There are a
multitude of third-party client
libraries that make this even easier
for a variety of programming languages
and environments.
The CouchDB website has more details. Happy coding!
find something erlang doesn't have that you understand and like. I did that with etap https://github.com/ngerakines/etap/ Now nick has taken over management and it's used internally at EA games. It was fun to make and like a previous poster it was something real so I learned to serve real world problems working on it.
File indexing/search system. This was going to by intro project but I've switched over to something else.
Once you've got it working you could move the indexes to mnesia, and then spread the thing out other nodes to a have a whole network index.

Resources