require 'spec_helper'
describe 'have_correct_syntax' do
describe 'ruby files' do
subject { '/test.rb' }
it 'checks if Ruby file has a proper syntax' do
stub_file subject, "class SomeClass\n def some_method\n puts 'Hello world!'\n end\nend"
expect(subject).to have_correct_syntax
end
it 'checks if Ruby file has an incorrect syntax' do
stub_file subject, "class SomeClass\ndef some_method\nputs 'Hello world!'"
expect(subject).to_not have_correct_syntax
end
end
describe 'erb files' do
subject { '/test.erb' }
it 'checks if simple ERB file has a proper syntax' do
stub_file subject, '<% if nonexistent_var == 1 %><% end %>'
expect(subject).to have_correct_syntax
end
it 'checks if simple ERB file has an incorrect syntax' do
stub_file subject, '<% if 1 + 1 %> abc'
expect(subject).to_not have_correct_syntax
end
it 'checks if complex ERB file has a proper syntax' do
stub_file subject, <<-EOF
<%= application_title %>
<%= element.id %> | <%= element.title %> | <%= link_to 'Show', element_path(element) %> |
This test should fail because I didn't close an each loop.
<% @elements.each do |element| %>