2012-11-12 02:01:49 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
require 'support/dummy_app'
|
2012-11-16 05:11:53 -05:00
|
|
|
require 'support/matchers/have_text'
|
2012-11-12 02:01:49 -05:00
|
|
|
|
2012-11-16 06:55:34 -05:00
|
|
|
app = DummyApp.new(ENV["RAILS_ENV"])
|
2013-01-18 12:10:37 -05:00
|
|
|
spec_types = {
|
|
|
|
view: ["/posts/1", "PostsController"],
|
|
|
|
mailer: ["/posts/1/mail", "PostMailer"]
|
|
|
|
}
|
2012-11-13 15:28:15 -05:00
|
|
|
|
2012-11-16 06:55:34 -05:00
|
|
|
app.start_server do
|
2013-01-18 12:10:37 -05:00
|
|
|
spec_types.each do |type, (path, controller)|
|
2012-11-16 06:55:34 -05:00
|
|
|
page = app.get(path)
|
2012-11-13 15:28:15 -05:00
|
|
|
|
2012-11-16 06:55:34 -05:00
|
|
|
describe "in a #{type}" do
|
|
|
|
it "runs in the correct environment" do
|
2013-01-16 21:36:56 -05:00
|
|
|
expect(page).to have_text(app.environment).in("#environment")
|
2012-11-16 06:55:34 -05:00
|
|
|
end
|
2012-11-12 02:01:49 -05:00
|
|
|
|
2013-01-18 12:10:37 -05:00
|
|
|
it "uses the correct view context controller" do
|
|
|
|
expect(page).to have_text(controller).in("#controller")
|
|
|
|
end
|
|
|
|
|
2013-01-16 11:30:53 -05:00
|
|
|
it "can use built-in helpers" do
|
2013-01-16 21:36:56 -05:00
|
|
|
expect(page).to have_text("Once upon a...").in("#truncated")
|
2013-01-16 11:30:53 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "can use built-in private helpers" do
|
|
|
|
# Nokogiri unescapes text!
|
2013-01-16 21:36:56 -05:00
|
|
|
expect(page).to have_text("<script>danger</script>").in("#html_escaped")
|
2013-01-16 11:30:53 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "can use user-defined helpers from app/helpers" do
|
2013-01-16 21:36:56 -05:00
|
|
|
expect(page).to have_text("Hello, world!").in("#hello_world")
|
2013-01-16 11:30:53 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "can use user-defined helpers from the controller" do
|
2013-01-16 21:36:56 -05:00
|
|
|
expect(page).to have_text("Goodnight, moon!").in("#goodnight_moon")
|
2013-01-16 11:30:53 -05:00
|
|
|
end
|
|
|
|
|
2013-07-14 11:03:16 -04:00
|
|
|
it "can be passed to path helpers" do
|
|
|
|
expect(page).to have_text("/en/posts/1").in("#path_with_decorator")
|
|
|
|
end
|
|
|
|
|
2012-11-16 06:55:34 -05:00
|
|
|
it "can use path helpers with a model" do
|
2013-01-16 21:36:56 -05:00
|
|
|
expect(page).to have_text("/en/posts/1").in("#path_with_model")
|
2012-11-16 06:55:34 -05:00
|
|
|
end
|
2012-11-12 02:01:49 -05:00
|
|
|
|
2012-11-16 06:55:34 -05:00
|
|
|
it "can use path helpers with an id" do
|
2013-01-16 21:36:56 -05:00
|
|
|
expect(page).to have_text("/en/posts/1").in("#path_with_id")
|
2012-11-12 02:01:49 -05:00
|
|
|
end
|
|
|
|
|
2013-07-14 11:03:16 -04:00
|
|
|
it "can be passed to url helpers" do
|
|
|
|
expect(page).to have_text("http://www.example.com:12345/en/posts/1").in("#url_with_decorator")
|
|
|
|
end
|
|
|
|
|
2012-11-16 06:55:34 -05:00
|
|
|
it "can use url helpers with a model" do
|
2013-01-16 21:36:56 -05:00
|
|
|
expect(page).to have_text("http://www.example.com:12345/en/posts/1").in("#url_with_model")
|
2012-11-16 06:55:34 -05:00
|
|
|
end
|
2012-11-12 02:01:49 -05:00
|
|
|
|
2012-11-16 06:55:34 -05:00
|
|
|
it "can use url helpers with an id" do
|
2013-01-16 21:36:56 -05:00
|
|
|
expect(page).to have_text("http://www.example.com:12345/en/posts/1").in("#url_with_id")
|
2012-11-12 02:01:49 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|