Sign Up Now!

Sign up and get personalized intelligence briefing delivered daily.


Sign Up

Articles related to "method"


Serverless Testing Strategies: Testing a Node.js + AWS Lambda + API Gateway app

  • For this article, we will build a Node.js serverless app and we’ll use the Serverless Framework and mocha.js to write and run our tests.
  • What we’re testing in the code above is just that the handler function receives the event object, handles it properly by checking for the “a” and “b” query parameters, calls asyncConcatService.concat and returns a proper response.
  • We’ve used sinon.js to mock the call to asyncConcatService.concat and fake its response as that function will be tested independently in the next unit test.
  • At least in some simple cases it’s possible but of course when we add more services such as AWS Cognito / SQS / SNS / Step functions / etc it’ll be more complicated to test the interfaces and the system as a whole, but using some of the patterns we’ve seen above creatively we can hopefully still write and run some tests !

save | comments | report | share on


Make your RSpec codes HALF. Introduction of RSpecZ extending RSpec for reviewers and developers.

  • RSpec codes are Long (means Hard to review).
  • It has methods of extending let, context and subject now.
  • I want RSpecZ to be a Guide of RSpec in the future so I will make generators, code analyzer and formatter and something like that.
  • This image is created by applying RSpecZ to a rspec code from a project I participated.
  • RSpec's context method is flexible and versatilie.
  • RSpec's context has no meaning by itself.
  • The above code means that set valid phone number to phone_number variable(let).
  • Reviewer can know valid specs will be written in the block when he read the method name.
  • RSpecZ has create_params method.
  • Actually, create_params define let with test-xxx characters if the param is not defined yet.
  • I will implement more useful let methods in the future.
  • RSpecZ has some other useful methods.

save | comments | report | share on


Untangling Nested Code

  • Let's take a look at a few examples of nested code and practices for improving their readability.
  • Nested code blocks often return a value.
  • When these are boolean values, there's an opportunity to condense the code block and return the condition directly.
  • Even for such a small number of lines this is hard to read, making the code appear more complex than it really is.
  • By identifying the conditional return of raw boolean values we have the rare opportunity to completely remove the nested code by directly returning the condition.
  • Given the context of this aptly named method combined with a now one line block, we decreased its perceived complexity.
  • We can refactor the conditional to a guard clause to unravel the nested code and expose the primary action.
  • It's a lot to read even if the contained blocks of code are only a few lines.

save | comments | report | share on


Mainstream election-forecasting could be improved by a popular academic approach

  • Forecasting the American presidential election usually relies on a clear-cut approach: first, modellers construct polling averages for each state.
  • The approach would allow forecasters to produce state-level estimates by applying sophisticated demographic modelling to a single, large national poll.
  • For example, the national poll would gather data about a large number of college-educated white women—including both their likely voting intention and chances of turning out on election day—and then estimate their differing impact in each state.
  • Some key state-level polls did not take account of this fissure before the election, producing bad estimates that contributed to the misfiring of poll-based forecasting models, like those at FiveThirtyEight and the New York Times.
  • Mr P promises to be a useful tool for forecasting future elections, and an application of the method correctly predicted that Donald Trump would win the presidency.

save | comments | report | share on


PayPal leads $50M round for PPRO, a profitable cross-border payment specialist

  • PayPal is leading a $50 million investment into PPRO, a London-based business that is focused on cross-border payments for merchants, specifically by offering the merchants a seamless way of accepting payments from customers using whatever the most popular payment form happens to be in a particular country.
  • For a merchant that is based in one country but interested in selling to people in another, this can pose a problem, if it doesn’t accept whatever the local payment method happens to be.
  • PayPal has an obvious agenda in hoping that its platform becomes to default for any transaction, and that is a big part of its strategic interest in PPRO, to provide PayPal as an option in the mix of payment acceptance methods wherever its nearly 20 million merchants happen to be doing business.

save | comments | report | share on


Implementing KISS

  • With so many possible paths, it’s so easy to feel overwhelmed to the point that I start trying to do several different things.
  • Often times I realize that my initial breakdown was not simple enough and I need to break it down even further (i.e. do one thing that I already know how to do or Google and find a point of reference quickly).
  • One way I’ve become better at KISS is by paying attention to other developers and putting new things I learn in my toolbox.
  • At this stage of the developer game, it’s much simpler to learn/accomplish one thing really well before moving on to something else (as opposed to trying to become good at 7 different things at one time).
  • I’m going to close out by saying that once I started keeping KISS as one of my goals, it has helped to keep me focused on a smaller scale.

save | comments | report | share on


Laravel Testing Woes: Token Mismatch

  • While that’s great, it’s probably pretty important to make POST/PUT/DELETE requests as well, right?
  • If you aren’t familiar with Laravel Middleware, go ahead and give it a read as it’s not too hard to understand.
  • It’s certainly worth verifying that line is present and the value is still set to testing.
  • At this point, you will want to start looking at setUp() methods, both in the test class you are inside of, and tests/TestCase.php.
  • If you still come up empty handed, it’s probably worth doing a search in the entire tests directory for the value that you see in $this['env'], and/or checking any sort of Vagrant/Homestad/Docker configuration files you might have.
  • While something changed in a test file somewhere is the likely culprit, it’s worth nothing that somebody could be particularly evil and change the environment in the application’s/request lifecycle before the middleware.

save | comments | report | share on