|
I used Jasmine (supposedly inspired by Rspec) for unit tests for one of my Javascript projects and loved it. If Test::Unit wasn't simple and Good Enough I'd have spent an hour or two on learning to use Rspec.
|
# ? Aug 18, 2013 01:13 |
|
|
# ? May 15, 2024 01:05 |
|
I've gone over to Rspec, with Rspec-given, Shoulda, and FactoryGirl. When I test. That's still my greatest weakness as a programmer.
|
# ? Aug 18, 2013 03:06 |
|
quote:What order are they coming in over the wire, before Rails has a chance to mangle it? According to the post params sniffed in the log, they come over in a proper integer order. So say a user enter a few records in this order: 23, 56, 24, 89. The post data for params[:foo_bar] that I sniff in the logs is sorted already as [23,24,56,89]. I suppose now I should look closer at the JS library I'm using for those form inputs? Seems really weird that RoR would auto-sort params -- but maybe it does? I mean, would it auto sort a set of string params by first character if I was posting strings instead of integers? Sounds kind of nutty.
|
# ? Aug 18, 2013 13:55 |
|
Form parameters are sent in the order they appear in the document. Double check that ordering. If that looks ok to you, look next at the raw POST data. You should see the same ordering there. Smol fucked around with this message at 16:38 on Aug 18, 2013 |
# ? Aug 18, 2013 16:31 |
|
Fillerbunny posted:I just came from the ChicagoRuby meetup where a couple guys from Hashrocket gave demos/presentations if how to use Rspec and Cucumber. Obviously they have different applications, especially where Cucumber is geared toward the front end. I'm definitely going to be looking into using it on my next project. Capybara is a great way to drive a web browser and scrape a web page. I ran the YOSPOS RIM death pool with it: https://www.dropbox.com/sh/2s2vaccgc6nnb2g/ZjDk3OSXn9 I like and respect the Hashrocket guys (their Chicago office is nice, but their Jacksonville Beach office is amazing, shame it's in Jacksonville) but rspec is dumb bullshit that goes too loving far:
|
# ? Aug 19, 2013 02:03 |
|
RSpec is fine if you throw the should syntax in the trash where it belongs. Also for more context: Deus Rex fucked around with this message at 09:47 on Aug 19, 2013 |
# ? Aug 19, 2013 09:44 |
|
Deus Rex posted:RSpec is fine if you throw the should syntax in the trash where it belongs. How do you write your specs? I find I have to fall back on the default it "should do something" do format when I'm relying on specs that make use of Whatever.should_receive. Am I thinking in the wrong order?
|
# ? Aug 19, 2013 14:13 |
|
with rspec, try and get in the habit of usingRuby code:
|
# ? Aug 19, 2013 15:11 |
|
Deus Rex posted:RSpec is fine if you throw the should syntax in the trash where it belongs. And that's kind of my other beef with rspec: you have to do maintenance because the syntax du jour changes all the loving time. code:
|
# ? Aug 19, 2013 15:43 |
|
While we're on the subject, one of the tests highlighted during the Hashrocket dude's demo was meant to simulate mitigating DDOS attacks, and used the following:Ruby code:
|
# ? Aug 19, 2013 15:48 |
|
soullessshoe posted:with rspec, try and get in the habit of using A lot of my specs just revolve around making sure that messages get passed to other objects. I use should_receive a lot. Can you give me an example of how I could rewrite this spec? code:
|
# ? Aug 19, 2013 17:40 |
|
I really like the idea behind the describe - it "should asgsgfsdg" do syntax. So that instead of several Test::Unit cases likecode:
code:
|
# ? Aug 19, 2013 17:53 |
|
prom candy posted:A lot of my specs just revolve around making sure that messages get passed to other objects. I use should_receive a lot. Can you give me an example of how I could rewrite this spec? I'd start by not checking balloon.state. Write a method on balloon called popped? (or inflated?) that checks the state. Then have your BalloonPopper call that method.
|
# ? Aug 19, 2013 18:05 |
|
I'm not really looking for a critique on the example code I wrote to explain my spec situation! I'm not actually writing an interface for balloons.
|
# ? Aug 19, 2013 18:20 |
|
prom candy posted:
https://www.relishapp.com/rspec/rspec-mocks/v/2-14/docs/message-expectations/expect-message-using-expect Ruby code:
|
# ? Aug 19, 2013 18:24 |
|
The main thing stopping me from using rspec is how bad the documentation is. It's not so much better than Test::Unit that I'm going to go out of my way to read when I could be learning something else.
|
# ? Aug 19, 2013 18:27 |
|
I really need to give cucumber a shot. The regex thing really turns me off, (not because I cant write regexes), it just seems like such an odd way of going about things. And if you're not really consistent with your syntax I expect it's super confusing to write. Is cucumber particularly well suited to anything, like view testing or integration testing? DONT THREAD ON ME fucked around with this message at 20:05 on Aug 19, 2013 |
# ? Aug 19, 2013 19:45 |
|
chumpchous posted:Is cucumber particularly well suited to anything, like view testing or integration testing? It's very very high level integration testing: I use it as a to-do list that checks itself off. I've heard that you should write scenarios in a way that you could use the same set of scenarios for HTML, iOS, and Android versions of an application. code:
|
# ? Aug 19, 2013 21:05 |
|
Cocoa Crispies posted:It's very very high level integration testing: I use it as a to-do list that checks itself off. I've heard that you should write scenarios in a way that you could use the same set of scenarios for HTML, iOS, and Android versions of an application. When I was writing heavy cucumber tests, I was going with the style of writing very generic, basic commands similar to what you have written and then making the step definitions more complex. My biggest problem with cucumber is that it's an awful idea to use for testing a heavy javascript front end. It can do it, but good lord it takes a long time. Our (moderately complex) web app took in the order of an hour to run the test suite. Granted a lot of that could have been the terrible decision to use ExtJS.
|
# ? Aug 19, 2013 23:25 |
|
Cocoa Crispies posted:https://www.relishapp.com/rspec/rspec-mocks/v/2-14/docs/message-expectations/expect-message-using-expect And why is this preferable to the should syntax?
|
# ? Aug 19, 2013 23:25 |
|
So I wrote and published my first gem, based on a need for a personal project. Basically, it allows you to include custom model methods in to_json/to_xml using a simple DSL instead of having to deal with overriding the methods yourself. It's kind of small and silly, but I didn't like how ugly it was to override the methods myself, plus I've been looking for a reason to write a gem that might actually get some use for awhile. Github link Would love to get any feedback/code critiques to learn from. I already learned a ton writing it
|
# ? Aug 19, 2013 23:32 |
|
prom candy posted:And why is this preferable to the should syntax? Some people don't like rspec adding Object#should and Object#should_not. Personally, I don't care.
|
# ? Aug 19, 2013 23:46 |
|
Cocoa Crispies posted:It's very very high level integration testing: I use it as a to-do list that checks itself off. I've heard that you should write scenarios in a way that you could use the same set of scenarios for HTML, iOS, and Android versions of an application. Okay that makes sense to me. This is kind of how I think of view testing (which I guess implicitly is integration testing), and I really hate doing it in Rspec/Capybara, so I'll give it a shot.
|
# ? Aug 20, 2013 00:08 |
|
kayakyakr posted:My biggest problem with cucumber is that it's an awful idea to use for testing a heavy javascript front end. It can do it, but good lord it takes a long time. Our (moderately complex) web app took in the order of an hour to run the test suite. Cucumber is awful once you get past the high-level happy case; that's when you want to consider something like Jasmine or Evergreen to test the JS independently of the Rails app, or use CI like Jenkins to move the slow tests out of your synchronous workflow. chumpchous posted:Okay that makes sense to me. This is kind of how I think of view testing (which I guess implicitly is integration testing), and I really hate doing it in Rspec/Capybara, so I'll give it a shot.
|
# ? Aug 20, 2013 03:56 |
|
It's serendipity that the thread turned to Cucumber, Rspec and TDD/BDD because I just finished reading The Cucumber Book. I am almost always a solo developer, so Cucumber's business jargon about stakeholders and team agreement really bugs me. It feels like silly MBA talk. But I'm giving Cucumber a try because I want to see if it can encourage me to do actual test-driven development instead of my usual habit of writing a couple tests, getting distracted by something in the app, writing half the app, then remembering I was supposed to be testing things. I'm using the Aruba gem with Cucumber on a small command line app I've been meaning to write. The gem provides baked in step definitions for testing command line apps, and it's actually pretty neat. It turns Cucumber into a magic test machine that automatically turns plain English like "When I run blah command, then the output should be blah" into working tests.
|
# ? Aug 20, 2013 06:53 |
|
Siguy posted:Cucumber's business jargon about stakeholders and team agreement really bugs me. It feels like silly MBA talk. It is silly MBA talk. Stakeholders that read or write specs in a stilted not-quite-English DSL exist only in the same universe as badass hair metal unicorns. Between the regex matching and the central conceit of interested and/or competent stakeholders, I can't shake the feeling Cucumber is a prank gone too far. poo poo, your terminal has to be 165 characters wide to read the drat cucumber --help output. Molten Llama fucked around with this message at 07:26 on Aug 20, 2013 |
# ? Aug 20, 2013 07:24 |
|
prom candy posted:And why is this preferable to the should syntax? For one thing, monkey patching is terrible and there's no excuse for a test suite to make extensive use of it. Just as importantly, it's impossible to test proxy objects with the should syntax. http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
# ? Aug 20, 2013 09:01 |
|
Monkey patching is all right if you can limit the scope, which is what refinements in 2.x try do. Unfortunately, the current implementation is quite problematic (especially for alternate ruby implementations). That said, they're much more useful in statically typed languages, where its easier to see where the added methods come from and where the compiler can and will do a lot of sanity checks about their use. Smol fucked around with this message at 16:52 on Aug 20, 2013 |
# ? Aug 20, 2013 16:45 |
|
I messed with cucumber pretty hard last night and I take back all of the bad things I ever said.
|
# ? Aug 20, 2013 16:49 |
|
I have three questions, but there's a wall o' text first. Background: I have to replace some existing apps that nobody likes with a Ruby on Rails web app. This app will have a back end API for other processes to send in data without going through the web pages. I'm vaguely aware of web services, and figured that would be the way to set up the API, assuming that it can be handled from the same rails server that is simultaneously handling the web app. I don't care whether I use a SOAP web service or a restful one (not entirely comfortable with the differences, but my requirements should be pretty simple database inserts and queries, so I imagine that can be done with either approach). I looked around, and it looks like the gems that let you plunk in web service functionality are old and not maintained, but that it's not supposed to be hard to do your own thing. Current: Working from this page, I made a GET route that can return just plain text in response to a request (which will probably be coming from curl commands in both R scripts and another Ruby script), and got a spot in my controller to render that text. I'll plan to use this to return completion codes and/or query results. I assume that setting up a post route will be similar, and that this is the way to return data to another process using the app. My questions: 1) The requests might be quite large, involving insertion of several related and linked database rows, and will need to be parsed and processed before returning a completion code. I want to have the user pass in some XML string, or maybe a JSON construct (unless there's a better option), but I have no idea how to get that data into the controller. Should it just be a url parameter of some sort, or is there a better way to get this done? Edit: I think I figured this one out - code:
2) Is this the right way to go about this, or should I be looking at some more formal web service setup, even if it uses outdated code? Or some other way of setting up the API entirely? 3) Ultimately, I want to restrict use to approved people, so random weirdos can't just post data to our database for fun and profit. Is there a standard way to enforce something like that? I assume we don't just want login and password data coming through GET/POST requests. Peristalsis fucked around with this message at 19:51 on Aug 20, 2013 |
# ? Aug 20, 2013 17:32 |
|
Siguy posted:I am almost always a solo developer, so Cucumber's business jargon about stakeholders and team agreement really bugs me. It feels like silly MBA talk. It's easy to get a non-technical stakeholder to sign off on scenarios that are written "properly." That's literally how Hashrocket runs their business, and why you see so many other consultancies using Cucumber.
|
# ? Aug 20, 2013 17:37 |
|
Peristalsis posted:My questions: 1) Put a number on "large." Kilobytes? Megabytes? Gigabytes? 2) Rails is a perfectly fine web service setup; Sinatra would work too, but past some complexity point I've always found myself wishing for Rails' structure. 3) The easy way is to use Basic auth and HTTPS so that login and password data coming through GET & POST requests isn't unencrypted on the wire.
|
# ? Aug 20, 2013 18:08 |
|
Peristalsis posted:I have three questions, but there's a wall o' text first. I would suggest making a standard rails app but instead of (or in addition to) html.erb files, write json.jbuilder views. Makes a pretty good web service endpoint. You can use basic auth + https and cookies to do that or you could implement an api key/secret thing. You might look into seeing if anyone else has implemented a jsonp renderer on top of jbuilder.
|
# ? Aug 20, 2013 18:28 |
|
Cocoa Crispies posted:1) Put a number on "large." Kilobytes? Megabytes? Gigabytes? Cocoa Crispies posted:2) Rails is a perfectly fine web service setup; Sinatra would work too, but past some complexity point I've always found myself wishing for Rails' structure. Cocoa Crispies posted:3) The easy way is to use Basic auth and HTTPS so that login and password data coming through GET & POST requests isn't unencrypted on the wire. kayakyakr posted:I would suggest making a standard rails app but instead of (or in addition to) html.erb files, write json.jbuilder views. Makes a pretty good web service endpoint. Thanks for the help. I feel better knowing that I'm not way off base trying to do it this way, and that just rendering non-HTML stuff is a way to return info to the calling code.
|
# ? Aug 20, 2013 20:05 |
|
Peristalsis posted:By "large", I just meant it could be a page or more of XML, and probably nobody would want to put all that text as a GET param in a URL. I noted above in an edit that I figured out how to make curl populate POST params, so hopefully that will be sufficient for this. What's "a page or more?" I'm going to assume it's under a few megabytes and jamming it in a POST body (that's not wrapped in form encoding) should work. Re: HTTP Basic auth: http://api.rubyonrails.org/classes/ActionController/HttpAuthentication/Basic.html
|
# ? Aug 20, 2013 20:45 |
|
Peristalsis posted:It's in addition to, but I'm inclined to stick with XML for the first version, if only because one of the people writing the client code isn't a programmer. He's more likely to be familiar with XML than with JSON. I'm also not sure he's going to like shoe-horning curl commands into his R scripts, but I guess he'll have to get over it. I found info on RCurl for him, so at least he shouldn't have to shell out to the OS to make it work. Eventually, I'd like to allow both approaches (XML and JSON), probably through different Rails routes. For XML use Builder: https://github.com/jimweirich/builder Don't use routing tricks, use the format parameter. Example: /users => html /users.json => json /users.xml => xml Rails knows, via respond_to/respond_with which views to render for each. Support all of the API languages in one shot and be happy. Use standard form posts and url params for bringing data in.
|
# ? Aug 20, 2013 20:52 |
|
Cocoa Crispies posted:What's "a page or more?" I'm going to assume it's under a few megabytes and jamming it in a POST body (that's not wrapped in form encoding) should work. I don't know exactly what the xml input will look like yet. We're not passing around the library of congress, but I expect that a worst case could be a text file of hundreds of lines. If I had more info, I'd give it to you. I thought I remembered that POST params are not limited in size, so that this should be a reasonable thing to pass around via HTTP. In any case, it seemed like a bad thing to put in a URL parameter. kayakyakr posted:For XML use Builder: kayakyakr posted:Don't use routing tricks, use the format parameter. Example: Thanks, I'll look into that, too. I don't think there will be an HTML version of most of the web services routes, but I'll definitely want to combine the XML and JSON in one place. Edit: I've probably been unclear - for the most part, I'll be reading the XML, and parsing it. I might pass back query results in XML, as well, but my main problem is passing the client's XML into my code and parsing it.
|
# ? Aug 20, 2013 21:24 |
|
Peristalsis posted:Edit: I've probably been unclear - for the most part, I'll be reading the XML, and parsing it. I might pass back query results in XML, as well, but my main problem is passing the client's XML into my code and parsing it. oh, gross. Umm, I'm still a fan of taking in data in a standard post body rather than encoded as an XML field. But there is middleware for that: https://github.com/rails/actionpack-xml_parser
|
# ? Aug 20, 2013 22:49 |
|
Anyone have thoughts on JBuilder vs. RABL for building a JSON API? I'm building an Angular app with a Rails backend and I don't think hacking around as_json is going to cut it as I've done in the past.
|
# ? Aug 21, 2013 03:09 |
|
|
# ? May 15, 2024 01:05 |
|
Deus Rex posted:Anyone have thoughts on JBuilder vs. RABL for building a JSON API? I'm building an Angular app with a Rails backend and I don't think hacking around as_json is going to cut it as I've done in the past. jbuilder is sorta the culmination of all of those that came before it. I really prefer jbuilder.
|
# ? Aug 21, 2013 03:52 |