Menu
abriraqui
  • reflexiones
  • publicaciones
  • hackership
  • experiencias
abriraqui

Wrapping up week 3 with integration tests #hackership

Posted on November 30, 2013December 28, 2013

Tweet

Slowly, we are coming to the end of week 3 of the hackership. Time flies but at the same time, the feeling is that everybody is a bit more tired now, learning requires a lot of energy!

Betahaus BreakfastThough is already the third Thursday I was surprised when I arrived at the Betahaus, of course, today is Beta Breakfast, so many co-workers are having breakfast together, then 3 start-ups will introduce themselves. Today I had a cup of coffee, stayed for a bit but decided to continue with integration tests, since is slow I’m not going to be able to finishis what I wanted to finish this week.

Today we skipped the stand up round, I guess too much of a mess when the Betabreakfast is going on, some stay in the breakfast, others arrive late, and most try to find a place somewhere else around the building, so we are scattered.
Ok, today I want to finish the integration tests, views, controllers, partials, css around events and try to do the user sign in of my app following the Michael Hartl tutorial…normally I would just use devise but since I’m doing everything form scratch I’ll stick to that.


require 'spec_helper'
feature 'events' do
before :each do
@event = Event.create(:name => "Printing the washing machine", :event_type => "Workshop", :day => Date.today)
end
scenario 'List of all the events' do
visit events_path
expect(page).to have_content('List of events')
expect(page).to have_content('Name')
expect(page).to have_content('Day')
expect(page).to have_content('Location')
expect(page).to have_content('Description')
expect(page).to have_content('Event type')
expect(page).to have_link('Edit', href: edit_event_path(@event))
expect(page).to have_link('Show', href: event_path(@event))
end

scenario ‘Create a new event’ do
visit events_path
click_link ‘New event’
expect(page).to have_content(‘Create new event’)
fill_in ‘Name’, with: ‘lala’
fill_in ‘Day’, with: Date.today
fill_in ‘Event type’, with: ‘Workshop’
click_button ‘Create event’
expect(page).to have_content(‘lala’)
expect(page).to have_link(‘Back’)
end

Ok, this time I’ll try to explain what happens in these tests

Step by step
require 'spec_helper' is a file that load certain configuration to take into account when running the tests

feature 'events' do
...
end

With a feature you are going to test the external interface, the web page. So in this case, we are going to do integration tests for the event model. For the features we need capybara.

before :each do
....
end

Then we see the before :each block, which means that this piece of code is going to be exectuted before each of the tests. In this case it will create an event before each test but it also will do the roll back at the end of the test, so each example is isolated, data are will be newly created each time.

scenario 'List of all the events' do
...
end

The scenario define what is it that you are going to test, in this case is to check that we see the list of all the events when going to the index page.
Then it comes the instructions of what is going to happen,
<code> visit events_path </code>  will look for /events, which is the index page

expect(page).to have_content('List of events') as it can be read, we expect the page to have the content “List of events”, and so on.

While doing the test we will be specifying in the events_controller that we want @events = Event.all, so that we have the data, that can be shown in a page, that we have to, that is the html for the index page in app/views/events/index.html.erb

The second scenario is a similar thing but for creating a new event, the actions needed in the controller (new and create) and the corresponging view (new.html.erb)

So that’s how you come to build the controllers and the views through TDD, a very slow process, but makes you understand things step by step.

To finish the day and the week, we had the follow-up round of presentations, but I must say that I think is not a good time, the end of the day in the last day of the week, not much energy left and everybody is tired, some are not there, at least my feeling is that is not the best time to concentrate and pay the right attention, maybe an after lunch thing would be better, who knows…just a thought.

But the day did not end there, during the day I received in my inbox a mail reminding of citizen kino #31 event, , run by xlterrestrials. I thought it was going to be the screening of the film I’m a cyborg and that’s ok and then some questioning around the topic, other approaches, etc. But actually was just the second part, several trailers, short videos, extracts from interviews and films thinking about what means to become cyborg, how the concept has change since it appeared in the 60s.

Citizen kino - I'm a cyborg and that is not ok

©2023 abriraqui | Powered by SuperbThemes & WordPress