| 1 | Sarah hi Zach!
|
| 2 | Zach M. Hey Sarah
|
| 3 | Sarah ok, I figured out my git problem :)
|
| 4 | Zach M. That's funny that you're patching an OpenLazlo plugin. I remember working with non-Rails OpenLazlo years ago
|
| 5 | Sarah u ready to dive in?
|
| 6 | Zach M. Sure, where do you need me to start?
|
| 7 | Sarah so, I just checked in some code that makes the specs run
|
| 8 | Sarah <a href="http://github.com/ultrasaurus/openlaszlo_plugin/commit/26fbaf78a9d5759a732c8cffc4cbb840003236e3" target="_blank">http://github.com/ultrasaurus/openlaszlo_p…</a>
|
| 9 | Sarah I dont' really understand why I needed to require 'action_controller' and friends in order to use assert_select (via RSpec's have_tag)
|
| 10 | Zach M. Yah
|
| 11 | Zach M. I was just going to ask that
|
| 12 | Zach M.
|
| 13 | <a href="/room/221003/paste/132377425" target="_blank">View paste</a>
|
| 14 | <br /><pre><code>+require 'action_controller'
|
| 15 | 0
|
| 16 | +require 'action_controller/assertions/selector_assertions'
|
| 17 | 0
|
| 18 | +include ActionController::Assertions::SelectorAssertions</code></pre>
|
| 19 |
|
| 20 | Zach M. Those don't seem necessary
|
| 21 | Zach M. lemme clone the code
|
| 22 | Sarah k
|
| 23 | Sarah the error I was getting before is written up here: <a href="http://www.ruby-forum.com/topic/187635#new" target="_blank">http://www.ruby-forum.com/topic/187635#new</a>
|
| 24 |
|
| 25 | Zach M. Hrm, I may know the probelm
|
| 26 | Sarah the failure happened in Rails 2.3.2 but not 2.1
|
| 27 | Zach M. hold on a sec, lemme situate my browser windows
|
| 28 | Sarah k
|
| 29 | Zach M. Interesting
|
| 30 | Sarah do tell
|
| 31 | Zach M. What's the difference between the plugin_spec_helper and spec_helper?
|
| 32 | Zach M. It looks like plugin_spec_helper is grabbing the spec of the Rails dir it's installed into?
|
| 33 | Sarah it wants the spec_helper from the Rails app
|
| 34 | Sarah I don't know why
|
| 35 | Sarah a colleague said he thought it had something to do with view testing
|
| 36 | Zach M. So you'll have to forgive me, I haven't written a ton of plugins. But the ones I've always written, I test it apart from a Rails install
|
| 37 | Zach M. A good example would be webrat
|
| 38 | Zach M. <a href="http://github.com/brynary/webrat/tree/master" target="_blank">http://github.com/brynary/webrat/tree/master</a>
|
| 39 | Zach M. openlaszlo_applet_specs.rb and swfobject_view_helper_spec.rb are the two main specs right? The others are just for environment setup?
|
| 40 | Zach M. It's interesting the way osteele set up the spec directory: <a href="http://github.com/osteele/openlaszlo_plugin/tree/bfe0bef882d23055d9fe6aa80447de26e14eedeb/spec" target="_blank">http://github.com/osteele/openlaszlo_plugi…</a>
|
| 41 |
|
| 42 | Zach M. Sorry, I'm trying to dig around the code to try and get a bit acquainted with it
|
| 43 | Zach M. This stuff may be needed:
|
| 44 | Zach M.
|
| 45 | <a href="/room/221003/paste/132378497" target="_blank">View paste</a>
|
| 46 | <br /><pre><code># just enough infrastructure to get 'assert_select' to work
|
| 47 | require 'action_controller'
|
| 48 | require 'action_controller/assertions/selector_assertions'
|
| 49 | include ActionController::Assertions::SelectorAssertions</code></pre>
|
| 50 |
|
| 51 | Zach M. Because it's only pulling in rspec
|
| 52 | Zach M. and rspec doesn't have assert_select, but rather rspec-rails does
|
| 53 | Sarah has left the room
|
| 54 | Sarah has entered the room
|
| 55 | Zach M. Welcome back :)
|
| 56 | Sarah not sure what happened there
|
| 57 | Zach M. heh, luckily, you can read the chat history
|
| 58 | Sarah I don't see any history
|
| 59 | Zach M. Oh no?
|
| 60 | Zach M. shoot
|
| 61 | Sarah I thought that was the point of campfire!
|
| 62 | Zach M. Try this: <a href="http://simplechatter.campfirenow.com/room/221003/transcript/2009/05/24" target="_blank">http://simplechatter.campfirenow.com/room/…</a>
|
| 63 |
|
| 64 | Zach M. Does that work?
|
| 65 | Sarah A. has entered the room
|
| 66 | Sarah A. hello
|
| 67 | Zach M. Hey
|
| 68 | Zach M. Having troubles?
|
| 69 | Sarah A. trying different browser
|
| 70 | Zach M. Ah
|
| 71 | Zach M. Here's a link to the transcripts: <a href="http://simplechatter.campfirenow.com/room/221003/transcript/2009/05/24" target="_blank">http://simplechatter.campfirenow.com/room/…</a>
|
| 72 |
|
| 73 | Sarah A. whenever I hit return, it would re-direct
|
| 74 | Zach M. Wierd
|
| 75 | Sarah A. that link required an email & password
|
| 76 | Zach M. bah
|
| 77 | Zach M. Here:
|
| 78 | Zach M.
|
| 79 | <a href="/room/221003/paste/132378842" target="_blank">View paste</a>
|
| 80 | <span class="number_of_lines">(<span>16 more lines</span>)</span> <br /><pre><code>a colleague said he thought it had something to do with view testing
|
| 81 | Zach M.
|
| 82 | So you'll have to forgive me, I haven't written a ton of plugins. But the ones I've always written, I test it apart from a Rails install
|
| 83 | Zach M.
|
| 84 | A good example would be webrat
|
| 85 | Zach M.
|
| 86 | http://github.com/brynary/webrat/tree/master
|
| 87 | Zach M.
|
| 88 | openlaszlo_applet_specs.rb and swfobject_view_helper_spec.rb are the two main specs right? The others are just for environment setup?
|
| 89 | Zach M.
|
| 90 | It's interesting the way osteele set up the spec directory: http://github.com/osteele/openlaszlo_plugi…
|
| 91 | May 24
|
| 92 | 1:10 PM
|
| 93 | Zach M.
|
| 94 | Sorry, I'm trying to dig around the code to try and get a bit acquainted with it
|
| 95 | ...</code></pre>
|
| 96 |
|
| 97 | Zach M. (Kinda nasty)
|
| 98 | Sarah A. I have the rspec-rails gem installed
|
| 99 | Sarah A. used to be a plugin when this plugin was written
|
| 100 | Sarah A. is there a way for me to just include it
|
| 101 | Sarah A. or something
|
| 102 | Zach M. Hrm. So conceptually, I'm thinking of this in 2 ways
|
| 103 | Zach M. You have you're rails install that this is embedded into
|
| 104 | Sarah A. btw: openlaszlo_applet_specs.rb and swfobject_view_helper_spec.rb are the main ones I'm using, but not the main point of the plugin
|
| 105 | Zach M. (and that rails install may have dependencies installed)
|
| 106 | Zach M. And you have your plugin with it's specs and possibly dependencies
|
| 107 | Sarah A. ok
|
| 108 | Zach M. What you're doing is embedding the plugin in order to test it. And therefore the Rails environment (with all it's dependencies) isn't loaded up
|
| 109 | Zach M. I guess my first question is, what are you wanting to accomplish?
|
| 110 | Sarah A. applet_view_helper.rb has a bug
|
| 111 | Zach M. Ah
|
| 112 | Sarah A. line 48 should read
|
| 113 | Sarah A. path = applet_path(source)
|
| 114 | Zach M. Gotcha
|
| 115 | Sarah A. I want to create a spec that fails
|
| 116 | Sarah A. and then fix the bug and have it pass
|
| 117 | Zach M. is there current coverage for that method?
|
| 118 | Sarah A. nope
|
| 119 | Sarah A. :)
|
| 120 | Ad Upgrade your Campfire account and say good-bye to ads. You'll also get more disk space, more chatters, SSL (on Plus and Premium plans), the ability to upload your own logo, and more. <strong>UPGRADE SPECIAL:</strong> Upgrade today and save $10 on your first month. Just enter coupon code CHATAD on the upgrade screen. To upgrade click the Account tab above.
|
| 121 | <p><small>Ads are only shown on free accounts. Upgrade to go ad free.</small></p>
|
| 122 |
|
| 123 | Zach M. hehe
|
| 124 | Zach M. Ok, so there's 3 options:
|
| 125 | Zach M. 1) You submit the github CODE change (without the specs)
|
| 126 | Zach M. 2) You keep working in the spec layout in order to create a new spec for that helper/method that fails/passes with your code change
|
| 127 | Zach M. 3) You revamp the way rspec is being used to test, and also include the spec for that code change
|
| 128 | Zach M. #3 is going to take the most effort, but you probably won't be as frustrated
|
| 129 | Sarah A. I don't mind doing #3... I have 2 goals
|
| 130 | Sarah A. 1) I will be using and living with this plugin for a while, so I want to be happy with it and comfortable making changes
|
| 131 | Sarah has left the room
|
| 132 | Sarah A. 2) I want to learn best practices for developing plugins and using RSpec, since we have tons of plugin in my day-job and we're moving to cucumber/Rspec in our new coding
|
| 133 | Zach M. Cool
|
| 134 | Sarah A. so
|
| 135 | Zach M. Ok, so if we started down the path of #3, I'd see a few things we'd need to do
|
| 136 | Zach M. On a highlevel, I should be able to checkout the plugin code and run the specs (without it being embedded in a Rails project)
|
| 137 | Sarah A. that would be very nice
|
| 138 | Zach M. (I may need to install some gems or deps to do that, but it's not dependent on the Rails install)
|
| 139 | Sarah A. but, can we test views without rails?
|
| 140 | Zach M. Second, I'd see the spec folder revamping quite a bit
|
| 141 | Zach M. So, you can still use rails and rails testing infrastructure without it being embedded in a Rails install
|
| 142 | Zach M. lemme grab a link from the Webrat plugin
|
| 143 | Sarah A. cool
|
| 144 | Zach M. Interesting, Webrat has changed quite a bit of their stuff
|
| 145 | Zach M. I'm not quite sure if you NEED to assert using view tests, but you may have to
|
| 146 | Zach M. One way you could do that would be to require rails as a gem. So it'll have the same effects as if it were embedded, but you don't have that "wrapper codebase"
|
| 147 | Zach M. You're already kinda doing that
|
| 148 | Zach M.
|
| 149 | <a href="/room/221003/paste/132379925" target="_blank">View paste</a>
|
| 150 | <br /><pre><code># just enough infrastructure to get 'assert_select' to work
|
| 151 | require 'action_controller'
|
| 152 | require 'action_controller/assertions/selector_assertions'
|
| 153 | include ActionController::Assertions::SelectorAssertions</code></pre>
|
| 154 |
|
| 155 | Sarah A. well... the bug I'm fixing happens when you add ?debug=true onto the page URL to get the OpenLaszlo app to compile with its embedded debugger
|
| 156 | Zach M. That may actually be grabbing the rubygems version of ActionController, not the wrapper code
|
| 157 | Sarah A. right
|
| 158 | Zach M. This is an interesting problem. I haven't had to test Helper code in a plugin before
|
| 159 | Zach M. Oh, you know what would be a good project to check out. RadiantCMS. They do a bit more messaging to create extensions, but I wonder if there may be some gems on how to setup the rspec and rspec-rails environment in order to test helpers
|
| 160 | Zach M. <a href="http://github.com/radiant/radiant/tree/master" target="_blank">http://github.com/radiant/radiant/tree/master</a>
|
| 161 | Zach M. Lemme see if I can gist some extension code i've written in the past
|
| 162 | Sarah A. cool
|
| 163 | Sarah A. I need to go away for 15 minutes and feed my kid breakfast
|
| 164 | Sarah A. can I ping you when I'm back?
|
| 165 | Zach M. Not a problem. I may be around.
|
| 166 | Zach M. One last thing
|
| 167 | Zach M. It looks like Radiant is doing the same thing as the "Embed inside rails" method
|
| 168 | Zach M.
|
| 169 | <a href="/room/221003/paste/132380249" target="_blank">View paste</a>
|
| 170 | <br /><pre><code>unless defined? RADIANT_ROOT
|
| 171 | ENV["RAILS_ENV"] = "test"
|
| 172 | require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../")}/config/boot"
|
| 173 | require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../")}/config/environment"
|
| 174 | end
|
| 175 |
|
| 176 | require 'spec/rails'</code></pre>
|
| 177 |
|
| 178 | Zach M. bummer
|
| 179 | Zach M. I'll check a bit more on this codebase, and maybe I can shoot you an email that may help you out
|
| 180 | Zach M. take care
|
| 181 | Sarah A. yeah, if you can send me some pointers on stuff to read
|
| 182 | Sarah A. then I can start getting up to speed, if you have to take off
|
| 183 | Zach M. Sounds good
|
| 184 | Sarah A. I'm back
|
| 185 | Zach M. Right on
|
| 186 | Zach M. Trying to make headway
|
| 187 | Zach M. Something is odd
|
| 188 | Zach M. Btw, in case you're curious. Radiant uses the same methodology: <a href="https://gist.github.com/cf7dff6a2620993654b8" target="_blank">https://gist.github.com/cf7dff6a2620993654b8</a>
|
| 189 |
|
| 190 | Zach M. (Except they embed rails and rspec differently)
|
| 191 | Zach M. But I created a new rails install just to make sure I'm not going insane:
|
| 192 | Zach M.
|
| 193 | <a href="/room/221003/paste/132382462" target="_blank">View paste</a>
|
| 194 | <br /><pre><code>require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
| 195 |
|
| 196 | describe DogHelper do
|
| 197 | it "should bark" do
|
| 198 | html = helper.bark
|
| 199 | html.should have_tag("script")
|
| 200 | end
|
| 201 |
|
| 202 | end
|
| 203 | </code></pre>
|
| 204 |
|
| 205 | Zach M. That fails but not on the assert_select deal
|
| 206 | Sarah A. did you make that as a plugin/spec or regular spec?
|
| 207 | Zach M. regular spec
|
| 208 | Zach M. perhaps I should create a new plugin/spec too
|
| 209 | Sarah A. well, it is a good idea to try stuff as a regular spec to test assumptions... I'll try that too
|
| 210 | Zach M. Yea, I'm a big "test assumptions" guy. Especially when things seem wacky
|
| 211 | Zach M. Something is plain funky
|
| 212 | Zach M. Real helper spec:
|
| 213 | Zach M.
|
| 214 | <a href="/room/221003/paste/132383016" target="_blank">View paste</a>
|
| 215 | <br /><pre><code>require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
| 216 |
|
| 217 | describe DogHelper do
|
| 218 | it "should bark" do
|
| 219 | html = helper.bark
|
| 220 | html.should have_tag("script")
|
| 221 | end
|
| 222 |
|
| 223 | end
|
| 224 | </code></pre>
|
| 225 |
|
| 226 | Zach M. And it's spec helper:
|
| 227 | Zach M.
|
| 228 | <a href="/room/221003/paste/132383031" target="_blank">View paste</a>
|
| 229 | <br /><pre><code># This file is copied to ~/spec when you run 'ruby script/generate rspec'
|
| 230 | # from the project root directory.
|
| 231 | ENV["RAILS_ENV"] ||= 'test'
|
| 232 | require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT)
|
| 233 | require 'spec/autorun'
|
| 234 | require 'spec/rails'
|
| 235 |
|
| 236 | Spec::Runner.configure do |config|
|
| 237 | # If you're not using ActiveRecord you should remove these
|
| 238 | # lines, delete config/database.yml and disable :active_record
|
| 239 | # in your config/boot.rb
|
| 240 | config.use_transactional_fixtures = true
|
| 241 | config.use_instantiated_fixtures = false
|
| 242 | config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
|
| 243 | end
|
| 244 | </code></pre>
|
| 245 |
|
| 246 | Zach M. Plugin helper:
|
| 247 | Zach M. (Er plugin helper spec):
|
| 248 | Zach M.
|
| 249 | <a href="/room/221003/paste/132383052" target="_blank">View paste</a>
|
| 250 | <br /><pre><code>require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
| 251 |
|
| 252 | describe DogHelper do
|
| 253 | it "should bark" do
|
| 254 | html = helper.bark
|
| 255 | html.should have_tag("script")
|
| 256 | end
|
| 257 |
|
| 258 | end
|
| 259 | </code></pre>
|
| 260 |
|
| 261 | Zach M. And it's spec_helper:
|
| 262 | Zach M. require File.dirname(__FILE__) + '/../../../../spec/spec_helper'
|
| 263 | Zach M.
|
| 264 | <a href="/room/221003/paste/132383078" target="_blank">View paste</a>
|
| 265 | <br /><pre><code>require File.dirname(__FILE__) + '/../../../../spec/spec_helper'
|
| 266 | </code></pre>
|
| 267 |
|
| 268 | Sarah A. is the have_tag part of webrat?
|
| 269 | Zach M. Getting same results with this:
|
| 270 | Zach M.
|
| 271 | <a href="/room/221003/paste/132383220" target="_blank">View paste</a>
|
| 272 | <br /><pre><code>require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
| 273 |
|
| 274 | describe DogHelper do
|
| 275 | include DogHelper
|
| 276 |
|
| 277 | it "should bark" do
|
| 278 | # html = helper.bark
|
| 279 | html = bark
|
| 280 | html.should have_tag("script")
|
| 281 | end
|
| 282 |
|
| 283 | end
|
| 284 | </code></pre>
|
| 285 |
|
| 286 | Zach M. Nah, it's part of rspec-rails
|
| 287 | Zach M. it's the thing calling assert_select
|
| 288 | Zach M. This spec code is giving me:
|
| 289 | Zach M.
|
| 290 | <a href="/room/221003/paste/132383276" target="_blank">View paste</a>
|
| 291 | <br /><pre><code>cairhien:helpers zmoazeni$ ruby dog_helper_spec.rb
|
| 292 | F
|
| 293 |
|
| 294 | 1)
|
| 295 | NoMethodError in 'DogHelper should bark'
|
| 296 | undefined method `assert_select' for #<ActiveSupport::TestCase::Subclass_1:0x22ba5dc>
|
| 297 | dog_helper_spec.rb:9:
|
| 298 | dog_helper_spec.rb:3:
|
| 299 | </code></pre>
|
| 300 |
|
| 301 | Sarah A. that's what I got before
|
| 302 | Zach M. I may have an idea
|
| 303 | Sarah A. do we need to require 'rspec-rails'
|
| 304 | Sarah A. or something?
|
| 305 | Zach M. If you put a print statement in the have_tag.rb, you'll see it's included
|
| 306 | Zach M. and that's inside rspec-rails
|
| 307 | Sarah A. well, at least I know it's not just crazy for me
|
| 308 | Zach M. I don't think RSpec knows it's a helper spec
|
| 309 | Zach M. Rspec loads the matchers based on what Type of spec it is Model, Controller, Helpers, Views
|
| 310 | Sarah A. The Rspec Book does not yet have a chapter on Rails helpers
|
| 311 | Zach M. That's why it's necessary to do:
|
| 312 | Zach M.
|
| 313 | <a href="/room/221003/paste/132383445" target="_blank">View paste</a>
|
| 314 | <br /><pre><code>describe DogHelper do
|
| 315 | include DogHelper</code></pre>
|
| 316 |
|
| 317 | Zach M. and not just:
|
| 318 | Zach M. describe DogHelper do
|
| 319 | Sarah A. did you write a DogHelper?
|
| 320 | Ad Campfire is just one of many simple and easy to use web-based tools designed by <a href="http://www.37signals.com" target="_blank">37signals</a>.
|
| 321 | <p><small>Ads are only shown on free accounts. Upgrade to go ad free.</small></p>
|
| 322 |
|
| 323 | Zach M. Yea
|
| 324 | Zach M. Bingo bango
|
| 325 | Zach M.
|
| 326 | <a href="/room/221003/paste/132383504" target="_blank">View paste</a>
|
| 327 | <br /><pre><code>require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
| 328 |
|
| 329 | describe DogHelper, :type => :helper do
|
| 330 |
|
| 331 | it "should bark" do
|
| 332 | html = helper.bark
|
| 333 | html.should have_tag("script")
|
| 334 | end
|
| 335 |
|
| 336 | end
|
| 337 | </code></pre>
|
| 338 |
|
| 339 | Zach M. That works
|
| 340 | Sarah A. ?
|
| 341 | Sarah A. ah
|
| 342 | Zach M. And that fixes the swfobject spec
|
| 343 | Zach M. Btw, this is the spec I have:
|
| 344 | Zach M.
|
| 345 | <a href="/room/221003/paste/132383609" target="_blank">View paste</a>
|
| 346 | <span class="number_of_lines">(<span>40 more lines</span>)</span> <br /><pre><code>require File.expand_path(File.dirname(__FILE__) + '/plugin_spec_helper')
|
| 347 | require File.expand_path(File.dirname(__FILE__) + "/../lib/swfobject_view_helper")
|
| 348 |
|
| 349 | # include ActionView::Helpers
|
| 350 |
|
| 351 | describe ActionView::Helpers::SwfObjectHelper, :type => :helper do
|
| 352 | # include ActionView::Helpers::SwfObjectHelper
|
| 353 |
|
| 354 | describe :swfobject_tag do
|
| 355 | # before(:each) do
|
| 356 | # ENV['RAILS_ENV'] = 'production'
|
| 357 | # self.stub!(:compute_public_path).and_return('/applets/url.swf')
|
| 358 | # end
|
| 359 |
|
| 360 | # it "should call swfobject.embedSWF" do
|
| 361 | ...</code></pre>
|
| 362 |
|
| 363 | Zach M. See I commented out the include, and I qualified the Spec (that way we don't have to include ActionView::Helpers
|
| 364 | Zach M. And this is the plugin_spec_helper:
|
| 365 | Zach M.
|
| 366 | <a href="/room/221003/paste/132383716" target="_blank">View paste</a>
|
| 367 | <br /><pre><code>begin
|
| 368 | require File.dirname(__FILE__) + '/../../../../spec/spec_helper'
|
| 369 | rescue LoadError
|
| 370 | puts "You need to install rspec in your base app"
|
| 371 | exit
|
| 372 | end
|
| 373 |
|
| 374 | # # just enough infrastructure to get 'assert_select' to work
|
| 375 | # require 'action_controller'
|
| 376 | # require 'action_controller/assertions/selector_assertions'
|
| 377 | # include ActionController::Assertions::SelectorAssertions</code></pre>
|
| 378 |
|
| 379 | Zach M. (You don't need that infrastructure
|
| 380 | Zach M. )
|
| 381 | Sarah A. I tried it here and it worked for me too!
|
| 382 | Zach M. I think the problem was, the infrastructure was there. RSpec didn't allow you to use it for that spec
|
| 383 | Sarah A. ah
|
| 384 | Zach M. One last thing:
|
| 385 | Zach M. This is dangerous:
|
| 386 | Zach M.
|
| 387 | <a href="/room/221003/paste/132383798" target="_blank">View paste</a>
|
| 388 | <br /><pre><code> # before(:each) do
|
| 389 | # ENV['RAILS_ENV'] = 'production'
|
| 390 | # self.stub!(:compute_public_path).and_return('/applets/url.swf')
|
| 391 | # end</code></pre>
|
| 392 |
|
| 393 | Sarah A. where is that?
|
| 394 | Zach M. Rails tests expect they are running in the "test" environment
|
| 395 | Zach M. Line 11ish of swfobject_view_helper.rb
|
| 396 | Zach M. I see there's some logic in the helper that switches based on whether it's in Production or Development
|
| 397 | Zach M. Instead of the Helper switching on ENV["RAILS_ENV"] I'd shove that into a small class like this:
|
| 398 | Zach M.
|
| 399 | <a href="/room/221003/paste/132384028" target="_blank">View paste</a>
|
| 400 | <br /><pre><code>class EnvChecker
|
| 401 | def production?
|
| 402 | ENV['RAILS_ENV'] == 'production'
|
| 403 | end
|
| 404 |
|
| 405 | def development?
|
| 406 | ENV['RAILS_ENV'] == 'development'
|
| 407 | end
|
| 408 | end</code></pre>
|
| 409 |
|
| 410 | Zach M. Then your "before(:each)" can stub that EnvChecker
|
| 411 | Zach M. Does that make sense?
|
| 412 | Sarah A. almost
|
| 413 | Sarah A. so... in the helper, use the EnvChecker class
|
| 414 | Zach M. yea
|
| 415 | Sarah A. then change the EnvChecker behavior (using mock?) in the before
|
| 416 | Zach M. yep
|
| 417 | Sarah A. rather than swithing the real env
|
| 418 | Sarah A. cool
|
| 419 | Zach M. I'll throw you a gist
|
| 420 | Sarah A. where would yu put the EnvChecker code?
|
| 421 | Zach M. somewhere in lib maybe
|
| 422 | Zach M. Lib may need some new directory cleanup. "helpers", "support" I dunno
|
| 423 | Sarah A. Lemme see if I can write it and run it by you
|
| 424 | Zach M. <a href="https://gist.github.com/71a30f8d26928dfe9663" target="_blank">https://gist.github.com/71a30f8d26928dfe9663</a>
|
| 425 | Zach M. That may be a bit clearer
|
| 426 | Sarah A. yes. thanks.
|
| 427 | Zach M. Is there anything else you need help on?
|
| 428 | Sarah A. yes...where do I find the docs for have_tag
|
| 429 | Zach M. hehe, hrm
|
| 430 | Sarah A. and for Rspec in general
|
| 431 | Zach M. This is rspec itself: <a href="http://rspec.rubyforge.org/rspec/1.2.6/" target="_blank">http://rspec.rubyforge.org/rspec/1.2.6/</a>
|
| 432 |
|
| 433 | Zach M. But the have_tag is in rspec-rails
|
| 434 | Sarah A. right
|
| 435 | Zach M. <a href="http://rspec.rubyforge.org/rspec-rails/1.2.6/" target="_blank">http://rspec.rubyforge.org/rspec-rails/1.2.6/</a>
|
| 436 | Zach M. have_tag: <a href="http://rspec.rubyforge.org/rspec-rails/1.2.6/classes/Spec/Rails/Matchers.html#M000064" target="_blank">http://rspec.rubyforge.org/rspec-rails/1.2…</a>
|
| 437 |
|
| 438 | Zach M. It's not all that clear though because it refers to this documentation: <a href="http://api.rubyonrails.org/classes/ActionController/Assertions/SelectorAssertions.html#M000547" target="_blank">http://api.rubyonrails.org/classes/ActionC…</a>
|
| 439 |
|
| 440 | Sarah A. I'm trying to understand line 36
|
| 441 | Sarah A. of swfobject_view_helper_spec.rb
|
| 442 | Sarah A. what /"8" means
|
| 443 | Sarah A. is that a regex?
|
| 444 | Zach M. Ah
|
| 445 | Zach M. it's actually:
|
| 446 | Zach M. /"8", \{/
|
| 447 | Zach M. yea
|
| 448 | Sarah A. this test fails
|
| 449 | Zach M. the regex starts and ends with //
|
| 450 | Sarah A. right
|
| 451 | Zach M. so the code says: "There is a 'script' tag and inside that there is the text '"8", {'"
|
| 452 | Sarah A. so... it looks like it is failing because the " doesn't match ' in the code
|
| 453 | Sarah A. also the version number is wrong
|
| 454 | Sarah A. or rather, not detailed enough
|
| 455 | Zach M. yep
|
| 456 | Sarah A. the default is: '8,0,24,0'
|
| 457 | Sarah A. but maybe that comes out with double-quotes in the code
|
| 458 | Sarah A. yup
|
| 459 | Zach M. I get knocked on a lot for debugging this way, but I'm a huge "print debugger":
|
| 460 | Zach M.
|
| 461 | <a href="/room/221003/paste/132385236" target="_blank">View paste</a>
|
| 462 | <br /><pre><code> it "should default to version 8" do
|
| 463 | html = swfobject_tag("url")
|
| 464 | puts html
|
| 465 | html.should have_tag('script', /"8", \{/)
|
| 466 | end</code></pre>
|
| 467 |
|
| 468 | Sarah A. well... just did 'view source' on the running app :)
|
| 469 | Zach M. heh
|
| 470 | Zach M. this is what running the test tells me:
|
| 471 | Zach M.
|
| 472 | <a href="/room/221003/paste/132385295" target="_blank">View paste</a>
|
| 473 | <br /><pre><code><div id="url">
|
| 474 | <p>Requires the Flash plugin. If the plugin is already installed, click <a href="?detectflash=false">here</a>.</p>
|
| 475 | </div>
|
| 476 | <script type="text/javascript">//<![CDATA[
|
| 477 |
|
| 478 | swfobject.embedSWF("/applets/url.swf", "url", "100%", "100%", "8,0,24,0", "/expressInstall.swf", {"lzproxied": false}, {"scale": "noscale"});
|
| 479 | //]]>
|
| 480 | </script>
|
| 481 | </code></pre>
|
| 482 |
|
| 483 | Zach M. I think it goes back to being a "Verify Assumptions"
|
| 484 | Zach M. er
|
| 485 | Sarah A. yup.. the code definitely specifes: '8,0,24,0'
|
| 486 | Zach M. I think it goes back to me being a "Verify Assumptions" coder
|
| 487 | Sarah A. I forget what is special about that version
|
| 488 | Sarah A. I'll just update the spec to match the code
|
| 489 | Sarah A. ok... now for my "real" question
|
| 490 | Zach M. haha
|
| 491 | Sarah A. I've created an example group (i guess they are called that) for applet_view_helper..
|
| 492 | Sarah A. and I have an example that passes
|
| 493 | Sarah A. now I want to write the failing example
|
| 494 | Sarah A. I need to test the view when I pass ?debug=true in the page that embeds the view
|
| 495 | Sarah A. does that make sense?
|
| 496 | Zach M. Sorta
|
| 497 | Zach M. So I'm guessing "?debug=true" will be a query param going to openlaszlo?
|
| 498 | Sarah A. so here's the use case:
|
| 499 | Ad From 37signals, the people who bring you Campfire: <a href="https://gettingreal.37signals.com" target="_blank">Getting Real, the book</a>. Discover the smarter, easier, faster way to build a successful web-based application. 171 pages.
|
| 500 | <p><small>Ads are only shown on free accounts. Upgrade to go ad free.</small></p>
|
| 501 |
|
| 502 | Sarah A. I have an app that manages a list of videos
|
| 503 | Sarah A. normally I would see a video detail page with this URL
|
| 504 | Sarah A. <a href="http://localhost:3000/videos/1" target="_blank">http://localhost:3000/videos/1</a>
|
| 505 | Sarah A. however, if I specify this URL: <a href="http://localhost:3000/videos/1?debug=true" target="_blank">http://localhost:3000/videos/1?debug=true</a>
|
| 506 |
|
| 507 | Sarah A. then the plugin will compile a different version of the app and name it whatever-debug.swf and refer to that URL
|
| 508 | Sarah A. (in the OpenLaszlo dev env ?debug=true will do the same thing, but the plugin will compile the swf in non-proxied mode, if you want to know the OL details)
|
| 509 | Sarah A. is that any clearer?
|
| 510 | Zach M. This may start getting outside my knowledge of how you integrate OL with Rails
|
| 511 | Sarah A. well.. the Rails question is:
|
| 512 | Zach M. I'm assuming that <a href="http://localhost:3000/videos/1" target="_blank">http://localhost:3000/videos/1</a> hits some regular controller, and in the view it uses helpers that point to tho OL server to compile, return the flash?
|
| 513 | Sarah A. yeah
|
| 514 | Sarah A. that's what the applet_tag helper does
|
| 515 | Zach M. gotcha
|
| 516 | Sarah A. it calls:
|
| 517 | Sarah A.
|
| 518 | <a href="/room/221003/paste/132385859" target="_blank">View paste</a>
|
| 519 | <br /><pre><code> if params.include?('debug')
|
| 520 |
|
| 521 | </code></pre>
|
| 522 |
|
| 523 | Zach M. So my high level concern would be, what if the application wanted to use "debug" ?
|
| 524 | Sarah A. so in the test, I need to send the param
|
| 525 | Sarah A. it can include that in the url string or as a canvas attribute inside the LZX
|
| 526 | Sarah A. but that would be rare
|
| 527 | Sarah A. usually you just want to use debug mode temporarily in development
|
| 528 | Zach M. Gotcha. Hrm. It seems like that param should be more obscure, or configurable
|
| 529 | Zach M. like olz_debug I dunno
|
| 530 | Sarah A. well, it is nice to have it be the same as it would be if you were deploying an OpenLaszlo server
|
| 531 | Sarah A. in production you would either not deploy the server (which is what I typically do) ...
|
| 532 | Sarah A. or you would lock it down to not allow this
|
| 533 | Zach M. Ok
|
| 534 | Sarah A. so... I need to know how to send the param in RSpec
|
| 535 | Sarah A. and I wasn't sure where to even look for that
|
| 536 | Zach M. So it doesn't sound like it'd have anything to do with the view right? Because you don't want conditional debugs littering your view. It sounds like it's the helper that would interpet 'params.include?("debug")'
|
| 537 | Zach M. I think you may be able to set the params in the "before", and if not, you can always use stubs to fake it out
|
| 538 | Sarah A. yes it does, (line 49)
|
| 539 | Zach M. Lemme check something
|
| 540 | Zach M. ok:
|
| 541 | Zach M.
|
| 542 | <a href="/room/221003/paste/132386281" target="_blank">View paste</a>
|
| 543 | <br /><pre><code>require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
| 544 |
|
| 545 | describe DogHelper do
|
| 546 | it "should bark" do
|
| 547 | params[:debug] = "foo"
|
| 548 | html = helper.bark
|
| 549 | html.should have_tag("script")
|
| 550 | end
|
| 551 | end
|
| 552 | </code></pre>
|
| 553 |
|
| 554 | Zach M.
|
| 555 | <a href="/room/221003/paste/132386289" target="_blank">View paste</a>
|
| 556 | <br /><pre><code>module DogHelper
|
| 557 | def bark
|
| 558 | p params
|
| 559 | "foo"
|
| 560 | end
|
| 561 | end
|
| 562 | </code></pre>
|
| 563 |
|
| 564 | Sarah A. that is exactly it
|
| 565 | Sarah A. ok... let me digest all this for a bit
|
| 566 | Zach M. hehe notta problem
|
| 567 | Sarah A. can I send you some code to review ?
|
| 568 | Zach M. Sure
|
| 569 | Sarah A. when I get further along...
|
| 570 | Zach M. I may not be able to get it to a point to run it
|
| 571 | Sarah A. thanks so much!
|
| 572 | Zach M. Hope you have a great weekend :) |