Skip to content

Commit

Permalink
Convert to i18n and add page objects
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaclayton committed Jul 17, 2015
1 parent ca1bb69 commit 2fa4a82
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 46 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@ group :test do
gem "capybara", "~> 2.4.4"
gem "database_cleaner"
gem "factory_girl_rails"
gem "formulaic"
gem "poltergeist"
end
5 changes: 5 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ GEM
factory_girl_rails (4.5.0)
factory_girl (~> 4.5.0)
railties (>= 3.0.0)
formulaic (0.3.0)
activesupport
capybara
i18n
globalid (0.3.5)
activesupport (>= 4.1.0)
i18n (0.7.0)
Expand Down Expand Up @@ -189,6 +193,7 @@ DEPENDENCIES
coffee-rails (~> 4.1.0)
database_cleaner
factory_girl_rails
formulaic
jbuilder (~> 2.0)
jquery-rails
poltergeist
Expand Down
4 changes: 2 additions & 2 deletions app/views/todos/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<%= link_to "Create todo", new_todo_path %>
<%= link_to t(".create_todo"), new_todo_path %>

<ul class="todos">
<% @todos.each do |todo| %>
<li class="<%= todo.complete? ? "completed" : "" %>">
<%= todo.title %>
<%= button_to "Mark complete", todo_completion_path(todo) %>
<%= button_to t(".mark_complete"), todo_completion_path(todo) %>
</li>
<% end %>
</ul>
2 changes: 1 addition & 1 deletion app/views/todos/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%= form_for @todo do |form| %>
<%= form.label :title %>
<%= form.text_field :title %>
<%= form.submit "Submit" %>
<%= form.submit %>
<% end %>
30 changes: 8 additions & 22 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
# Files in the config/locales directory are used for internationalization
# and are automatically loaded by Rails. If you want to use locales other
# than English, add the necessary files in this directory.
#
# To use the locales, use `I18n.t`:
#
# I18n.t 'hello'
#
# In views, this is aliased to just `t`:
#
# <%= t('hello') %>
#
# To use a different locale, set it with `I18n.locale`:
#
# I18n.locale = :es
#
# This would use the information in config/locales/es.yml.
#
# To learn more, please read the Rails Internationalization guide
# available at http://guides.rubyonrails.org/i18n.html.

en:
hello: "Hello world"
todos:
index:
create_todo: "Create a todo"
mark_complete: "Mark complete"
helpers:
submit:
todo:
create: "Create todo"
17 changes: 5 additions & 12 deletions spec/features/user_completes_a_todo_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,12 @@
feature "User completes a todo" do
scenario "successfully" do
sign_in
create_todo_titled title: "Buy eggs"
create_todo_titled title: "Buy milk"

within "li:contains('Buy eggs')" do
click_on "Mark complete"
end
todos_page = Pages::Todos.new
todos_page.create_todo title: "Buy eggs"
todos_page.create_todo title: "Buy milk"
todos_page.mark_complete "Buy eggs"

expect(page).to have_css "ul.todos li.completed", text: "Buy eggs"
end

def create_todo_titled(title:)
click_on "Create todo"
fill_in "Title", with: title
click_on "Submit"
expect(todos_page).to have_completed_todo_titled "Buy eggs"
end
end
12 changes: 4 additions & 8 deletions spec/features/user_creates_todo_spec.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
require "rails_helper"

feature "User creates todo", js: true do
feature "User creates todo" do
scenario "successfully" do
sign_in
create_todo_titled title: "Buy eggs"

expect(page).to have_css "ul.todos", text: "Buy eggs"
end
todos_page = Pages::Todos.new
todos_page.create_todo title: "Buy eggs"

def create_todo_titled(title:)
click_on "Create todo"
fill_in "Title", with: title
click_on "Submit"
expect(todos_page).to have_todo_titled "Buy eggs"
end
end
3 changes: 2 additions & 1 deletion spec/features/user_views_todos_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

sign_in_as email: "me@example.com"

expect(page).not_to have_css "ul.todos", text: "Buy milk"
todos_page = Pages::Todos.new
expect(todos_page).not_to have_todo_titled "Buy milk"
end
end
18 changes: 18 additions & 0 deletions spec/support/features/pages/new_todo.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module Pages
class NewTodo
include Capybara::DSL
include Formulaic::Dsl

def initialize(attributes)
@attributes = attributes
end

def create
fill_form_and_submit :todo, attributes
end

private

attr_reader :attributes
end
end
35 changes: 35 additions & 0 deletions spec/support/features/pages/todos.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module Pages
class Todos
include Capybara::DSL

def create_todo(attributes)
create_todo_link.click

Pages::NewTodo.new(attributes).create
end

def has_todo_titled?(title)
todos_list.has_css? "li", text: title
end

def has_completed_todo_titled?(title)
todos_list.has_css? "li.completed", text: title
end

def mark_complete(title)
within "li:contains('#{title}')" do
click_on I18n.t("todos.index.mark_complete")
end
end

private

def todos_list
find("ul.todos")
end

def create_todo_link
find_link I18n.t("todos.index.create_todo")
end
end
end

0 comments on commit 2fa4a82

Please sign in to comment.