Comments (13)
+1 I see this bug tooo
from rabl.
Don't you want to assert that when you're making that controller request that the response contains the correct template? Why would you not want to do that?
from rabl.
I would argue that since stubbing views is the default behavior of rspec-rails, that rabl should make sure it works for that default case.
I waffle back and forth on "view specs are a great idea! Test your view in isolation!"... and "View specs are a horrible idea, because you need to remember to test your views along with everything, and the view you forget to test will be the one that throws an error...". And I know you can turn render_views
on for a context...
from rabl.
The problem with stubbing the view is that most of us then use Cucumber to test the actual "use" of the views. That doesn't work really well in the case of JSON output IMHO.
I use json_spec and verify the output in RSpec. I can't handle the wordy Cuke tests show in the json_spec's README to test output. To me, the specifics of my JSON output is a unit test (= spec) and testing the use of the JSON output within my application is a true integration test (= cuke).
In other words, I use RSpec to test controllers and RABL and Cucumber for view usage and browser like stuff.
I can look into requiring render_views
to work but I'm just curious how you guys test the output.
from rabl.
I'm having the same issue here. I was confused as to whether it's rspec-rails or rabl that is the issue. Following the code with debugger, through both haml and rabl, it seems like the issue with rabl is that even with render_views turned off the compiled rabl template gets executed while the haml template gets compiled but not executed. In either case, I feel like rspec-rails should cut off the templates at a higher level than it is doing now... but maybe I'm wrong and rabl should be tweaked?
Here is the issue I posted in rspec-rails: rspec/rspec-rails#565
from rabl.
I'll look at it later tonight but at first glance, RSpec is substituting the view_path on the controller such that it finds their empty template instead of the proper one.
Rabl itself does the template lookup here: https://github.com/nesquena/rabl/blob/master/lib/rabl/partials.rb#L66
Eventually it calls context_scope.lookup_context.find
which, when you look at the Rails source, is basically used in the same way - to find the file within the view_path. I'll have to dig into a project that I have that uses rspec to see what's possible.
I'd hate to make a change to Rspec to support this change but if Haml is having the same results, maybe some common pattern can evolve so that any template renderer works.
from rabl.
Hmm in my specs that's never getting called -- that seems to only be used for partial rendering within rabl.
from rabl.
Ok, so I tracked it down:
Basically, RSpec stubs out templates to seem empty rather than stubbing out the whole rendering process. It does this so Rails properly handles formats/mime-types/etc. and seeing if templates are missing. When this code runs:
def self.call(template)
source = if template.source.empty?
File.read(template.identifier)
else # use source
template.source
end
%{ ::Rabl::Engine.new(#{source.inspect}).
render(self, assigns.merge(local_assigns)) }
end # call
rabl sees an "empty" source and re-loads it from the file system. I'm not sure where the change should happen here. On the one hand, rspec-rails could accomodate template engines that don't like blank source code. On the other, rabl could maybe be refactored... but I think that would be harder than making a simple change to rspec-rails. I left my thoughts in the rspec-rails chain... but if anyone else has thoughts I would love to hear them!
from rabl.
(continue from the rspec-rails thread)
@databyte -- that commit replaced something that would have also been trouble:
def compile(template)
%{
::Rabl::Engine.new(#{File.read(template.identifier).inspect}).render(self, assigns.merge(local_assigns))
}
end
I guess it could be: ::Rabl::Engine.new(#{template.source.inspect}).render(self, assigns.merge(local_assigns))
instead. But I wonder if that breaks anything in Rails 2.x?
from rabl.
Rails 2.x uses a different template read and the used of source = template.source
is how ERB does it. See:
Give me a min to run a full spec suite on an app that I have that uses Rabl to make sure everything is still clean.
from rabl.
Cool -- I commented on issue #35. It turns out @mrinterweb was using rspec without render_views
so the source was empty for good reason. It's a bit nuts that that pull request was merged for very much the wrong reasons. It should definitely be template.source
:)
from rabl.
And thank you for your help with this! Had me pulling my hair out all day. I'm used to testing my controller in isolation, so when I introduced rabl for a lot of my json stuff today, I couldn't figure out why things were not going as expected. At least I have a very intimate understanding of the Rails template system now :).
(Btw -- we met at a NYC ruby meet up a while back, no?)
from rabl.
That should fix it and my tests that previously didn't use render_views but needed to are now breaking as they should.
I believe we may have met though there was a time I went to a lot of them. Are you going to GoRuCo?
from rabl.
Related Issues (20)
- Drop riot? Unmaintained, broken on Ruby 2.5. HOT 2
- How to use rabl with swagger? HOT 2
- Tagging a new version, or use master branch? HOT 1
- Unable to properly render json for an simple array of objects HOT 1
- How do I render free form metadata HOT 1
- Migrating to Rails 5 - Rabl returning Active Record object
- Rspec renders rabl as string instead of json
- Not able to get the rendered result in Rails console HOT 1
- Rabl output values as keys
- Rabl partial lookup based on requested api namespace
- upgrading from 0.14.0 to 0.14.1 is a breaking change HOT 8
- Child removes node from response when the provided object is an empty array HOT 2
- Rabl not renders collection properly HOT 4
- Is nested map valid in RABL?
- N+1 issues HOT 1
- some problems to install rable on windows HOT 2
- Avoid playing with `Oj` shared `default_options` HOT 2
- rabl tests failing with rr 3.x and Ruby 3 HOT 12
- Rails 7 compatibility HOT 1
- access controller instance variables in representers
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rabl.